Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Intent myIntent = new Intent(MainActivity.this , CheckUpdateService.class);
  2. AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
  3. PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);
  4. Calendar calendar = Calendar.getInstance();
  5. calendar.set(Calendar.HOUR_OF_DAY, 12);
  6. calendar.set(Calendar.MINUTE, 00);
  7. calendar.set(Calendar.SECOND, 00);
  8. alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours
  9.  
  10. public class CheckAppsUpdateService extends Service {
  11.  
  12. private GetJSONData update_notif_service;
  13.  
  14. public CheckAppsUpdateService() {
  15. }
  16.  
  17. @Override
  18. public IBinder onBind(Intent intent) {
  19. //throw new UnsupportedOperationException("Not yet implemented");
  20. return null;
  21. }
  22.  
  23. @Override
  24. public void onStart(Intent intent, int startId) {
  25. super.onStart(intent, startId);
  26. }
  27.  
  28. @Override
  29. public int onStartCommand(Intent intent, int flags, int startId) {
  30.  
  31. ConnectionStatusDetector csd = new ConnectionStatusDetector(this);
  32.  
  33. if (csd.isConnectingToInternet()) {
  34. try {
  35. // execute an asycntask here for getting Json data from server
  36. }catch (Exception e){
  37. Log.e("Update service error", "nothing");
  38. }
  39. }
  40. return super.onStartCommand(intent, flags, startId);
  41. }
  42.  
  43. @Override
  44. public void onDestroy() {
  45. super.onDestroy();
  46. if (update_notif_service != null && update_notif_service.getStatus() == AsyncTask.Status.RUNNING) {
  47. update_notif_service.cancel(true);
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement