我正在使用本教程,我想生成通知
//prepare intent如果
//已选择通知
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]")
.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
行中有错误,eclipse说the method addaction(ing, String pendingintent) is undefined for the type notification.builder
最佳答案
您需要将sdkTargetVersion
元素中的<uses-sdk>
设置为16或更高。对于较旧版本的android,AndroidManifest.xml
方法不存在。