Java Code Examples for android.app.PendingIntent#FLAG_CANCEL_CURRENT

The following examples show how to use android.app.PendingIntent#FLAG_CANCEL_CURRENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyMessagingService.java    From Pharmacy-Android with GNU General Public License v3.0 6 votes vote down vote up
private void createOrderUpdateNotification(RemoteMessage.Notification notification, Map<String, String> data) {

        Context context = getBaseContext();
        String orderId = data.get("order_id");
        String type = data.get("type");

        Intent orderDetailIntent = OrderDetailActivity.getInstanceByOrderId(context, orderId);
        int requestID = (int) System.currentTimeMillis(); //unique requestID to differentiate between various notification with same NotifId
        int flags = PendingIntent.FLAG_CANCEL_CURRENT; // cancel old intent and create new one
        PendingIntent pIntent = PendingIntent.getActivity(this, requestID, orderDetailIntent, flags);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(notification.getTitle())
                .setContentText(notification.getBody())
                .setSound(alarmSound)
                .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                .setContentIntent(pIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(orderId,ORDER_UPDATE_NOTIFICATION_ID, mBuilder.build());
    }
 
Example 2
Source File: ExoHelper.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Restart the application by setting a PendingIntent on the AlarmManager and then killing the
 * current process.
 *
 * @param context any current context from the application
 */
public static void restartApp(Context context) {
  Context appContext = context.getApplicationContext();
  final Intent launchIntent =
      appContext
          .getPackageManager()
          .getLaunchIntentForPackage(appContext.getPackageName())
          .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  // Can be anything so long as it's unique. This part of the sha1sum of "buck"
  int id = 0xe354735f;
  final int flags =
      PendingIntent.FLAG_CANCEL_CURRENT
          | PendingIntent.FLAG_IMMUTABLE
          | PendingIntent.FLAG_ONE_SHOT;
  PendingIntent pendingIntent = PendingIntent.getActivity(appContext, id, launchIntent, flags);
  AlarmManager am = appContext.getSystemService(AlarmManager.class);
  long deadline = System.currentTimeMillis() + 500L;
  am.setExact(AlarmManager.RTC_WAKEUP, deadline, pendingIntent);
  Process.killProcess(Process.myPid());
}
 
Example 3
Source File: UpdateService.java    From coolreader with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void createConsolidatedNotification(NotificationManager mNotificationManager, int updateCount, int newCount, int newNovel) {
	Log.d(TAG, "set consolidated Notification");
	Notification notification = getNotificationTemplate(true);
	CharSequence contentTitle = "BakaReader EX Updates";
	String contentText = "Found";
	if (updateCount > 0) {
		contentText += " " + updateCount + " updated chapter(s)";
	}
	if (newCount > 0) {
		if (updateCount > 0)
			contentText += " and ";
		contentText += " " + newCount + " new chapter(s)";
	}
	if (newNovel > 0) {
		if (updateCount > 0 || newCount > 0)
			contentText += " and ";
		contentText += " " + newNovel + " new novel(s)";
	}
	contentText += ".";

	Intent notificationIntent = new Intent(this, MainTabActivity.class);
	notificationIntent.putExtra(Constants.EXTRA_CALLER_ACTIVITY, UpdateService.class.toString());
	int pendingFlag = PendingIntent.FLAG_CANCEL_CURRENT;
	PendingIntent contentIntent = PendingIntent.getActivity(this, Constants.CONSOLIDATED_NOTIFIER_ID, notificationIntent, pendingFlag);

	notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
	mNotificationManager.notify(Constants.CONSOLIDATED_NOTIFIER_ID, notification);
}
 
Example 4
Source File: UpdateService.java    From coolreader with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public void prepareNotification(final int notifId, UpdateInfoModel chapter, Notification notification) {
	CharSequence contentTitle = chapter.getUpdateType().toString();
	CharSequence contentText = chapter.getUpdateTitle();

	Intent notificationIntent = new Intent(this, MainTabActivity.class);
	notificationIntent.putExtra(Constants.EXTRA_PAGE, chapter.getUpdatePage());

	int pendingFlag = PendingIntent.FLAG_CANCEL_CURRENT;
	PendingIntent contentIntent = PendingIntent.getActivity(this, notifId, notificationIntent, pendingFlag);

	notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
}