[英]Android Notification use PendingIntent not new one
我已经在我的应用程序中实现了一些通知。 似乎每次我单击通知都会启动新的意图。 目标是将应用程序置于前台,因为它仍在后台(因此不会被杀死)。
我该如何实现?
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, ChatActivity.class), 0);
long[] vibration = new long[]{100, 250};
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setAutoCancel(true)
.setTicker(msg)
.setLights(Color.WHITE, 300, 600)
.setSound(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.new_msg))
.setVibrate(vibration)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
要将应用程序置于最前面,请在“待定意图”中使用以下意图。
Intent intent = new Intent(this, ChatActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
如果尚未终止应用程序,它将恢复该应用程序;如果已终止它,则将打开ChatActivity。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.