【发布时间】:2017-01-18 10:18:21
【问题描述】:
我正在开发 Android 中的可操作通知。
void createActionableNotification() {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// Build notification
// Actions are just fake
Notification noti = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject").setSmallIcon(R.drawable.moneybag)
.setContentIntent(pIntent)
.addAction(R.drawable.moneybag, "Call", pIntent)
.addAction(R.drawable.moneybag, "More", pIntent)
.addAction(R.drawable.moneybag, "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);
}
应用程序正在使用目标 SDK 运行,编译 SDK API 为 24,Min SDK 为 20。 我用 Marshmallow Device 进行了测试。但在模拟器中它工作正常。模拟器 SDK 版本为 24
【问题讨论】:
标签: android android-notifications android-notification-bar