List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:com.android.mms.transaction.MessagingNotification.java
private static void notifyFailed(Context context, boolean isDownload, long threadId, boolean noisy) { // TODO factor out common code for creating notifications boolean enabled = MessagingPreferenceActivity.getNotificationEnabled(context); if (!enabled) { return;/* w ww. ja va 2 s .c o m*/ } // Strategy: // a. If there is a single failure notification, tapping on the notification goes // to the compose view. // b. If there are two failure it stays in the thread view. Selecting one undelivered // thread will dismiss one undelivered notification but will still display the // notification.If you select the 2nd undelivered one it will dismiss the notification. int totalFailedCount = getUndeliveredMessageCount(context); Intent failedIntent; Notification notification = new Notification(); String title; String description; if (totalFailedCount > 1) { description = context.getString(R.string.notification_failed_multiple, Integer.toString(totalFailedCount)); title = context.getString(R.string.notification_failed_multiple_title); } else { title = isDownload ? context.getString(R.string.message_download_failed_title) : context.getString(R.string.message_send_failed_title); description = context.getString(R.string.message_failed_body); } TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // Get failed intent by folder mode or conversation mode. if (MessageUtils.isMailboxMode()) { failedIntent = getFailedIntentFromFolderMode(context, totalFailedCount, isDownload); if (failedIntent == null) { return; } else if (isDownload) { // When isDownload is true, the valid threadId is passed into this function. failedIntent.putExtra(FAILED_DOWNLOAD_FLAG, true); } else { failedIntent.putExtra(UNDELIVERED_FLAG, true); } } else { failedIntent = getFailedIntentFromConversationMode(context, isDownload, threadId); } taskStackBuilder.addNextIntent(failedIntent); notification.icon = R.drawable.stat_notify_sms_failed; notification.tickerText = title; notification.setLatestEventInfo(context, title, description, taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); if (noisy) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false /* don't vibrate by default */); if (vibrate) { notification.defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr); } NotificationManager notificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (isDownload) { notificationMgr.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification); } else { notificationMgr.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification); } }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
@Override public void onCreate() { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Native init jni_init();//from w ww . j a va 2s .c o m boolean pcap = prefs.getBoolean("pcap", false); setPcap(pcap, this); prefs.registerOnSharedPreferenceChangeListener(this); Util.setTheme(this); super.onCreate(); HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command"); HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log"); HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats"); commandThread.start(); logThread.start(); statsThread.start(); commandLooper = commandThread.getLooper(); logLooper = logThread.getLooper(); statsLooper = statsThread.getLooper(); commandHandler = new CommandHandler(commandLooper); logHandler = new LogHandler(logLooper); statsHandler = new StatsHandler(statsLooper); // Listen for interactive state changes last_interactive = Util.isInteractive(this); IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED); registerReceiver(interactiveStateReceiver, ifInteractive); // Listen for power save mode if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); powersaving = pm.isPowerSaveMode(); IntentFilter ifPower = new IntentFilter(); ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); registerReceiver(powerSaveReceiver, ifPower); } // Listen for user switches if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); registerReceiver(userReceiver, ifUser); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Listen for idle mode state changes IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); registerReceiver(idleStateReceiver, ifIdle); } // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityChangedReceiver, ifConnectivity); // Listen for added applications IntentFilter ifPackage = new IntentFilter(); ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addDataScheme("package"); registerReceiver(packageAddedReceiver, ifPackage); // Setup house holding Intent alarmIntent = new Intent(this, ServiceSinkhole.class); alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private Notification getEnforcingNotification(int allowed, int blocked, int hosts) { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_started)).setContentIntent(pi).setColor(tv.data) .setOngoing(true).setAutoCancel(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET) .setPriority(Notification.PRIORITY_MIN); }//from w w w . j a v a 2s. co m if (allowed > 0 || blocked > 0 || hosts > 0) { NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_started)); if (Util.isPlayStoreInstall(this)) notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked)); else notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts)); return notification.build(); } else return builder.build(); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private Notification getWaitingNotification() { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_waiting)).setContentIntent(pi).setColor(tv.data) .setOngoing(true).setAutoCancel(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET) .setPriority(Notification.PRIORITY_MIN); }/*from w w w. j av a 2s . co m*/ return builder.build(); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private void showDisabledNotification() { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi).setColor(tv.data) .setOngoing(false).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); }/*from w w w . j a v a2 s. c o m*/ NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_revoked)); NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build()); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private void showAutoStartNotification() { Intent main = new Intent(this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_APPROVE, true); PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_autostart)).setContentIntent(pi).setColor(tv.data) .setOngoing(false).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); }// w ww. j a va2 s .co m NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_autostart)); NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build()); }
From source file:me.spadival.podmode.PodModeService.java
/** Updates the notification. */ void updateNotification(String text) { PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification.Builder(getApplicationContext()).setContentTitle("PodMode") .setContentText(text).setContentIntent(pi).setSmallIcon(R.drawable.ic_stat_podmode) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setOngoing(true) .getNotification();/*from www . j a v a 2 s. co m*/ mNotificationManager.notify(NOTIFICATION_ID, mNotification); }
From source file:eu.faircode.adblocker.ServiceSinkhole.java
private void showExitNotification(String reason) { Intent main = new Intent(this, ActivityMain.class); PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.msg_error)).setContentIntent(pi).setColor(tv.data) .setOngoing(false).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET); }/* ww w . j av a 2 s.c om*/ NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_error)); notification.setSummaryText(reason); NotificationManagerCompat.from(this).notify(NOTIFY_EXIT, notification.build()); }
From source file:co.beem.project.beem.FbTextService.java
private PendingIntent makeChatIntent(User user) { Intent chatIntent = new Intent(FbTextService.this, FbTextMainActivity.class); chatIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); try {/* w w w . ja v a2 s . co m*/ chatIntent.setData(user.toUri()); } catch (Exception e) { if (FbTextApplication.isDebug) Log.e(TAG, e.getMessage()); } PendingIntent contentIntent = PendingIntent.getActivity(FbTextService.this, 0, chatIntent, PendingIntent.FLAG_UPDATE_CURRENT); return contentIntent; }
From source file:me.spadival.podmode.PodModeService.java
/** * Configures service as a foreground service. A foreground service is a * service that's doing something the user is actively aware of (such as * playing music), and must appear to the user as a notification. That's why * we create the notification here.// w w w .j a v a2s. c om */ void setUpAsForeground(String text) { PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); mNotification = new Notification.Builder(getApplicationContext()).setContentTitle("PodMode") .setContentText(text).setContentIntent(pi).setSmallIcon(R.drawable.ic_stat_podmode) .setContentIntent(pi) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setOngoing(true) .getNotification(); startForeground(NOTIFICATION_ID, mNotification); }