【发布时间】:2014-09-08 04:32:57
【问题描述】:
我有一个带有三个按钮的简单通知。单击按钮后如何调用自定义函数。我红了,说这里应该用pending intent,但是没找到有用的例子。
这是我的代码:
PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
// I WOULD LIKE TO CALL THIS INTENT OR CUSTOM FUNCTION
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "123456789"));
// build notification
// the addAction re-use the same intent to keep the example short
Notification n = new Notification.Builder(context)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setAutoCancel(true)
.addAction(R.drawable.ic_launcher, "Call", phoneCallIntent) //CUSTOM INTENT OR FUNCTION CALLING
.addAction(R.drawable.ic_launcher, "More", pIntent)
.addAction(R.drawable.ic_launcher, "And more", pIntent)
.build();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
请问我该怎么做?
感谢您的帮助。
【问题讨论】:
标签: android android-notifications android-pendingintent