List of usage examples for android.content Intent FLAG_FROM_BACKGROUND
int FLAG_FROM_BACKGROUND
To view the source code for android.content Intent FLAG_FROM_BACKGROUND.
Click Source Link
From source file:com.snappy.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras, String messageData) {//from w w w . j av a 2 s. co m if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } Log.i(LOG_TAG, message); Log.i(LOG_TAG, fromName); }
From source file:org.tasks.gtasks.GoogleTaskSyncAdapter.java
private void sendNotification(Context context, Intent intent) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND); PendingIntent resolve = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentIntent(resolve).setContentTitle(context.getString(R.string.sync_error_permissions)) .setContentText(context.getString(R.string.common_google_play_services_notification_ticker)) .setAutoCancel(true).setSmallIcon(android.R.drawable.ic_dialog_alert) .setTicker(context.getString(R.string.common_google_play_services_notification_ticker)); notificationManager.notify(Constants.NOTIFICATION_SYNC_ERROR, builder.build()); }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from ww w . j a va2 s . c o m private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:com.tenforwardconsulting.cordova.bgloc.BackgroundGeolocationPlugin.java
public ComponentName startBackgroundService() { if (isEnabled) { return null; }//from ww w.ja va 2 s .c om Activity activity = this.cordova.getActivity(); Log.d(TAG, "Starting bg service"); locationServiceIntent = new Intent(activity, LocationService.class); locationServiceIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); // locationServiceIntent.putExtra("config", config.toParcel().marshall()); locationServiceIntent.putExtra("config", config); isEnabled = true; return activity.startService(locationServiceIntent); }
From source file:org.adaway.helper.ResultHelper.java
/** * Private helper used in showNotificationBasedOnResult * * @param context// w w w . j a va2 s . co m * @param title * @param text * @param statusText * @param result * @param iconStatus * @param numberOfSuccessfulDownloads * @param showDialog */ private static void processResult(Context context, String title, String text, String statusText, int result, int iconStatus, String numberOfSuccessfulDownloads, boolean showDialog) { if (Utils.isInForeground(context)) { if (showDialog) { // start BaseActivity with result Intent resultIntent = new Intent(context, BaseActivity.class); resultIntent.putExtra(BaseActivity.EXTRA_APPLYING_RESULT, result); if (numberOfSuccessfulDownloads != null) { resultIntent.putExtra(BaseActivity.EXTRA_NUMBER_OF_SUCCESSFUL_DOWNLOADS, numberOfSuccessfulDownloads); } resultIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(resultIntent); } } else { // show notification showResultNotification(context, title, text, result, numberOfSuccessfulDownloads); } if (numberOfSuccessfulDownloads != null) { BaseActivity.setStatusBroadcast(context, title, statusText + " " + numberOfSuccessfulDownloads, iconStatus); } else { BaseActivity.setStatusBroadcast(context, title, statusText, iconStatus); } }
From source file:com.cerema.cloud2.syncadapter.FileSyncAdapter.java
/** * Notifies the user about a failed synchronization through the status notification bar *///ww w.ja v a 2 s.co m private void notifyFailedSynchronization() { NotificationCompat.Builder notificationBuilder = createNotificationBuilder(); boolean needsToUpdateCredentials = (mLastFailedResult != null && (mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED || mLastFailedResult.isIdPRedirection())); if (needsToUpdateCredentials) { // let the user update credentials with one click Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount()); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND); notificationBuilder.setTicker(i18n(R.string.sync_fail_ticker_unauthorized)) .setContentTitle(i18n(R.string.sync_fail_ticker_unauthorized)) .setContentIntent(PendingIntent.getActivity(getContext(), (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT)) .setContentText(i18n(R.string.sync_fail_content_unauthorized, getAccount().name)); } else { notificationBuilder.setTicker(i18n(R.string.sync_fail_ticker)) .setContentTitle(i18n(R.string.sync_fail_ticker)) .setContentText(i18n(R.string.sync_fail_content, getAccount().name)); } showNotification(R.string.sync_fail_ticker, notificationBuilder); }
From source file:org.telegram.messenger.NotificationsController.java
public void processNewMessages(final ArrayList<MessageObject> messageObjects, final boolean isLast) { if (messageObjects.isEmpty()) { return;//w ww . ja v a2 s . c o m } final ArrayList<MessageObject> popupArray = new ArrayList<>(popupMessages); notificationsQueue.postRunnable(new Runnable() { @Override public void run() { boolean added = false; int oldCount = popupArray.size(); HashMap<Long, Boolean> settingsCache = new HashMap<>(); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int popup = 0; for (int a = 0; a < messageObjects.size(); a++) { MessageObject messageObject = messageObjects.get(a); long mid = messageObject.messageOwner.id; if (messageObject.messageOwner.to_id.channel_id != 0) { mid |= ((long) messageObject.messageOwner.to_id.channel_id) << 32; } if (pushMessagesDict.containsKey(mid)) { continue; } long dialog_id = messageObject.getDialogId(); long original_dialog_id = dialog_id; if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) { playInChatSound(); continue; } if ((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) { dialog_id = messageObject.messageOwner.from_id; } if (isPersonalMessage(messageObject)) { personal_count++; } added = true; Boolean value = settingsCache.get(dialog_id); boolean isChat = (int) dialog_id < 0; popup = (int) dialog_id == 0 ? 0 : preferences.getInt(isChat ? "popupGroup" : "popupAll", 0); if (value == null) { int notifyOverride = getNotifyOverride(preferences, dialog_id); value = !(notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || isChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0); settingsCache.put(dialog_id, value); } if (value) { if (popup != 0) { popupArray.add(0, messageObject); } delayedPushMessages.add(messageObject); pushMessages.add(0, messageObject); pushMessagesDict.put(mid, messageObject); if (original_dialog_id != dialog_id) { pushDialogsOverrideMention.put(original_dialog_id, 1); } } } if (added) { notifyCheck = isLast; } if (!popupArray.isEmpty() && oldCount != popupArray.size() && !AndroidUtilities.needShowPasscode(false)) { final int popupFinal = popup; AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { popupMessages = popupArray; if (ApplicationLoader.mainInterfacePaused || !ApplicationLoader.isScreenOn && !UserConfig.isWaitingForPasscodeEnter) { MessageObject messageObject = messageObjects.get(0); if (popupFinal == 3 || popupFinal == 1 && ApplicationLoader.isScreenOn || popupFinal == 2 && !ApplicationLoader.isScreenOn) { Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class); popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND); ApplicationLoader.applicationContext.startActivity(popupIntent); } } } }); } } }); }
From source file:com.ferdi2005.secondgram.NotificationsController.java
protected void forceShowPopupForReply() { notificationsQueue.postRunnable(new Runnable() { @Override/*from ww w .j ava 2 s.com*/ public void run() { final ArrayList<MessageObject> popupArray = new ArrayList<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if (messageObject.messageOwner.mentioned && messageObject.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage || (int) dialog_id == 0 || messageObject.messageOwner.to_id.channel_id != 0 && !messageObject.isMegagroup()) { continue; } popupArray.add(0, messageObject); } if (!popupArray.isEmpty() && !AndroidUtilities.needShowPasscode(false)) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { popupReplyMessages = popupArray; Intent popupIntent = new Intent(ApplicationLoader.applicationContext, PopupNotificationActivity.class); popupIntent.putExtra("force", true); popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_FROM_BACKGROUND); ApplicationLoader.applicationContext.startActivity(popupIntent); Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); ApplicationLoader.applicationContext.sendBroadcast(it); } }); } } }); }
From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java
protected void startBackgroundService() { if (!isServiceRunning) { log.info("Starting bg service"); Activity activity = getActivity(); Intent locationServiceIntent = new Intent(activity, LocationService.class); locationServiceIntent.putExtra("config", config); locationServiceIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); // start service to keep service running even if no clients are bound to it activity.startService(locationServiceIntent); isServiceRunning = true;/*from w w w. ja v a2s . c o m*/ } }
From source file:com.digitalarx.android.files.services.FileDownloader.java
/** * Updates the status notification with the result of a download operation. * // w w w.j a v a2s .co m * @param downloadResult Result of the download operation. * @param download Finished download operation */ private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) { mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker); if (!downloadResult.isCancelled()) { int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker : R.string.downloader_download_failed_ticker; boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED || downloadResult.isIdPRedirection()); tickerId = (needsToUpdateCredentials) ? R.string.downloader_download_failed_credentials_error : tickerId; mNotificationBuilder.setTicker(getString(tickerId)).setContentTitle(getString(tickerId)) .setAutoCancel(true).setOngoing(false).setProgress(0, 0, false); if (needsToUpdateCredentials) { // let the user update credentials with one click Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, download.getAccount()); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND); mNotificationBuilder.setContentIntent(PendingIntent.getActivity(this, (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT)); mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials } else { // TODO put something smart in showDetailsIntent Intent showDetailsIntent = new Intent(); mNotificationBuilder.setContentIntent( PendingIntent.getActivity(this, (int) System.currentTimeMillis(), showDetailsIntent, 0)); } mNotificationBuilder.setContentText( ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources())); mNotificationManager.notify(tickerId, mNotificationBuilder.build()); // Remove success notification if (downloadResult.isSuccess()) { // Sleep 2 seconds, so show the notification before remove it NotificationDelayer.cancelWithDelay(mNotificationManager, R.string.downloader_download_succeeded_ticker, 2000); } } }