List of usage examples for android.support.v4.content WakefulBroadcastReceiver completeWakefulIntent
public static boolean completeWakefulIntent(Intent intent)
From source file:kr.ac.kookmin.cs.firstcoin.pos.data.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();//from w ww . ja v a 2 s . c o m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that * GCM will be extended in the future with new message types, just * ignore any message types you're not interested in, or that you * don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. /* * for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + * 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { * Thread.sleep(5000); } catch (InterruptedException e) { } } */ Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); }
From source file:eu.codeplumbers.cosi.services.CosiContactService.java
@Override protected void onHandleIntent(Intent intent) { // Do the task here Log.i(CosiContactService.class.getName(), "Cosi Service running"); // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); allContacts = new ArrayList<>(); Device device = Device.registeredDevice(); // cozy register device url designUrl = device.getUrl() + "/ds-api/request/contact/all/"; syncUrl = device.getUrl() + "/ds-api/data/"; // concatenate username and password with colon for authentication final String credentials = device.getLogin() + ":" + device.getPassword(); authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); showNotification();/*from w w w . ja v a2s . co m*/ if (isNetworkAvailable()) { try { // read local sms log first readContactDatabase(); EventBus.getDefault().post(new CallSyncEvent(SYNC_MESSAGE, "Getting remote contacts from Cozy...")); getRemoteContacts(); mBuilder.setContentText(getString(R.string.lbl_contacts_sync_done)); mBuilder.setProgress(0, 0, false); mNotifyManager.notify(notification_id, mBuilder.build()); mNotifyManager.cancel(notification_id); sendChangesToCozy(); mNotifyManager.cancel(notification_id); EventBus.getDefault().post(new ContactSyncEvent(REFRESH, "Sync OK")); } catch (Exception e) { e.printStackTrace(); mSyncRunning = false; EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); } } else { mSyncRunning = false; EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, "No Internet connection")); mBuilder.setContentText("Sync failed because no Internet connection was available"); mNotifyManager.notify(notification_id, mBuilder.build()); } }
From source file:com.example.notification.gcm.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w w w . j a v a 2 s . c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that * GCM will be extended in the future with new message types, just * ignore any message types you're not interested in, or that you * don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. // for (int i = 0; i < 5; i++) { // Log.i(TAG, "Working... " + (i + 1) // + "/5 @ " + SystemClock.elapsedRealtime()); // try { // Thread.sleep(5000); // } catch (InterruptedException e) { // } // } // Log.i(TAG, "Completed work @ " + // SystemClock.elapsedRealtime()); // Post notification of received message. msg = extras.toString(); status = extras.getString("status"); check = extras.getString("check"); notifier = "From: " + extras.getString("notifier"); dbAdapter = new DatabaseAdapter(this); dbAdapter.open(); title = notifier; body = "The status is " + status + " " + " Detail: " + check; dbAdapter.addNotif(title, body); // add notification into database sendNotification("Received: " + "Something happened. Let's solve it quickly!"); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. WakefulBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.google.android.apps.dashclock.DashClockService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent")); enforceCallingPermission(DashClockExtension.PERMISSION_READ_EXTENSION_DATA); if (intent != null) { String action = intent.getAction(); if (ACTION_UPDATE_WIDGETS.equals(action)) { handleUpdateWidgets(intent); } else if (ACTION_UPDATE_EXTENSIONS.equals(action)) { handleUpdateExtensions(intent); }/*from w w w . j av a 2 s . c o m*/ // If started by a wakeful broadcast receiver, release the wake lock it acquired. WakefulBroadcastReceiver.completeWakefulIntent(intent); } return START_STICKY; }
From source file:com.actinarium.nagbox.service.NagboxService.java
@Override protected void onHandleIntent(Intent intent) { if (intent == null) { return;// w ww . j a va 2 s. com } // I know that only either of those is needed, but for the sake of nice code I'm pulling these here final Task task = intent.getParcelableExtra(EXTRA_TASK); final long id = intent.getLongExtra(EXTRA_TASK_ID, Task.NO_ID); switch (intent.getAction()) { case ACTION_UPDATE_TASK_STATUS: handleUpdateTaskStatus(task); break; case ACTION_ON_ALARM_FIRED: handleOnAlarmFired(); break; case ACTION_ON_NOTIFICATION_DISMISSED: handleOnNotificationDismissed(id); break; case ACTION_ON_NOTIFICATION_ACTION_STOP_TASK: int notificationIdToCancel = intent.getIntExtra(EXTRA_CANCEL_NOTIFICATION_ID, -1); handleStopTaskById(id, notificationIdToCancel); break; case ACTION_CREATE_TASK: handleCreateTask(task); break; case ACTION_UPDATE_TASK: handleUpdateTask(task); break; case ACTION_DELETE_TASK: handleDeleteTask(id); break; case ACTION_RESTORE_TASK: handleRestoreTask(task); break; } // Release the wake lock, if there was any. WakefulBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
@WorkerThread private void handleOnAlarmReceived(Intent intent) { Timber.d("Handling onAlarmReceived"); try {//from www . j ava 2 s. c om processOldEvents(); refreshNotificationDisplay(); setNextAlarm(); } finally { WakefulBroadcastReceiver.completeWakefulIntent(intent); } }
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
@WorkerThread private void handleOnTimeChanged(Intent intent) { Timber.d("Handling onTimeChanged"); try {//from w ww . j a va2 s. c o m // ignores snooze; time change events should happen only when // - user is currently traveling (probably does not care deeply about doing sports) // - DST change, deep at night // - user wilfully plays around with their system time settings (we're not caring for that) recalculateNextOccForAll(); setNextAlarm(); } finally { WakefulBroadcastReceiver.completeWakefulIntent(intent); } }
From source file:org.microg.gms.gcm.McsService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { synchronized (McsService.class) { if (rootHandler != null) { if (intent == null) return START_REDELIVER_INTENT; wakeLock.acquire(WAKELOCK_TIMEOUT); Object reason = intent.hasExtra(EXTRA_REASON) ? intent.getExtras().get(EXTRA_REASON) : intent; if (ACTION_CONNECT.equals(intent.getAction())) { rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, reason)); } else if (ACTION_HEARTBEAT.equals(intent.getAction())) { rootHandler.sendMessage(rootHandler.obtainMessage(MSG_HEARTBEAT, reason)); } else if (ACTION_SEND.equals(intent.getAction())) { handleSendMessage(intent); }//from w w w . j a v a 2 s.c o m WakefulBroadcastReceiver.completeWakefulIntent(intent); } else if (connectIntent == null) { connectIntent = intent; } else { WakefulBroadcastReceiver.completeWakefulIntent(intent); } } return START_REDELIVER_INTENT; }
From source file:com.numenta.core.service.DataService.java
@Override protected void onHandleIntent(Intent intent) { Log.i(TAG, "onHandleIntent:"); // Force data synchronization try {//from w ww . j a va2s . co m _dataSyncService.synchronizeWithServer(); } catch (IOException e) { Log.e(TAG, "Unable to connect", e); } // Handle the case when the intent was sent from the AlarmManger if (intent != null) { WakefulBroadcastReceiver.completeWakefulIntent(intent); } }