我正在使用这个教程http://www.vogella.com/articles/AndroidNotifications/article.html http://www.vogella.com/articles/AndroidNotifications/article.html,我想建立通知
// 准备意图,如果
// 通知被选择
Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "[email protected] /cdn-cgi/l/email-protection")
.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);
我的线路有错误addAction
,日食说the method addaction(ing, String pendingintent) is undefined for the type notification.builder
您需要设置您的sdkTargetVersion
in the <uses-sdk>
的元素AndroidManifest.xml
16岁或以上。这addAction(...)
旧版本的 Android 不存在该方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)