android.app.PendingIntent#FLAG_CANCEL_CURRENT源码实例Demo

下面列出了android.app.PendingIntent#FLAG_CANCEL_CURRENT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Pharmacy-Android   文件: MyMessagingService.java
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());
    }
 
源代码2 项目: buck   文件: ExoHelper.java
/**
 * 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());
}
 
源代码3 项目: coolreader   文件: UpdateService.java
@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);
}
 
源代码4 项目: coolreader   文件: UpdateService.java
@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);
}