Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Intent myIntent = new Intent(MainActivity.this , CheckUpdateService.class);
- AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
- PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.HOUR_OF_DAY, 12);
- calendar.set(Calendar.MINUTE, 00);
- calendar.set(Calendar.SECOND, 00);
- alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent); //set repeating every 24 hours
- public class CheckAppsUpdateService extends Service {
- private GetJSONData update_notif_service;
- public CheckAppsUpdateService() {
- }
- @Override
- public IBinder onBind(Intent intent) {
- //throw new UnsupportedOperationException("Not yet implemented");
- return null;
- }
- @Override
- public void onStart(Intent intent, int startId) {
- super.onStart(intent, startId);
- }
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- ConnectionStatusDetector csd = new ConnectionStatusDetector(this);
- if (csd.isConnectingToInternet()) {
- try {
- // execute an asycntask here for getting Json data from server
- }catch (Exception e){
- Log.e("Update service error", "nothing");
- }
- }
- return super.onStartCommand(intent, flags, startId);
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (update_notif_service != null && update_notif_service.getStatus() == AsyncTask.Status.RUNNING) {
- update_notif_service.cancel(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement