通过AlarmManager启动服务时,我使用以下代码启动通知:
nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "App";
CharSequence message = "Getting Latest Info...";
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
Notification notif = new Notification(R.drawable.icon,
"Getting Latest Info...", System.currentTimeMillis());
notif.setLatestEventInfo(this, from, message, contentIntent);
nm.notify(1, notif);
Run Code Online (Sandbox Code Playgroud)
如何设置此项目的意图,以便当用户点击它时,它会启动某个活动?
当用户点击通知时,清除通知编号的最佳方法是什么?我说最好的方法,但我真的没有找到任何方式.当用户点击通知时,我正在启动一个内置活动,而不是我写的东西,所以我不能那样清除它.我已将通知管理器的标志设置为清除
NotificationManager notification
.
.
.
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.number++;
nm.notify(1,notification);
Run Code Online (Sandbox Code Playgroud)
但无论我做什么,Notification.number都会继续上升,永远不会重置为0.