【发布时间】:2014-07-28 04:08:40
【问题描述】:
我正在阅读tutorial 的待定意图以及它如何与通知管理器一起使用。
在该页面中,提到了以下代码:
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.addAction(R.drawable.icon, "Call", pIntent)
.addAction(R.drawable.icon, "More", pIntent)
.addAction(R.drawable.icon, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
我想问一下为什么需要为通知管理器提供待处理的意图(为什么它需要我的应用程序的身份来发送意图)?
为什么不能只给出一个意图?
编辑:请不要回答待定意图的定义。我知道待定意图是什么。我感兴趣的是为什么通知不能只使用带有诸如 startActivity() 之类的 API 的正常意图。
【问题讨论】:
标签: android android-intent android-pendingintent