来自 BroadcastReceiver 的通知 PendingIntent
Notification PendingIntent from BroadcastReceiver
伙计们。
我已经调试了好几天了,但找不到答案。
正如标题所说,我正在使用 BroadcastReceiver
进行通知。
一切都很好,直到我添加 .addAction
。
默认需要PendingIntent
,我做了一个PendingIntent
。
但问题是这样的;当我添加 .addAction
时,它显示为
Incompatiable types.
Required : android.app.Notification
Found : android.app.Notification.Builder
代码在没有 .addAction
和 PendingIntent
的情况下工作得很好。
可能是什么问题?
这是我的代码,
BroadcastReceiver
,WifiService.java
Intent intent = new Intent(mcontext, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pIntent = PendingIntent.getActivity(mcontext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification noti = new Notification.Builder(mcontext)
.setContentTitle("Welcome home!")
.setContentText("You have a to-do; " + hometodo)
.setSmallIcon(R.drawable.home_light)
.setLargeIcon(icon)
.setLights(0xFFFFD800, 5000, 0)
.addAction(R.drawable.archive_notification, "Mark as done", pIntent);
//.addAction gets the error.
.build();
NotificationManager notificationManager = (NotificationManager) mcontext.getSystemService(mcontext.NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
使用 NotificationCompat
设置 .addAction(...)
。
action buttons won't appear on platforms prior to Android 4.1. Action
buttons depend on expanded notifications, which are only available in
Android 4.1 and later.
伙计们。
我已经调试了好几天了,但找不到答案。
正如标题所说,我正在使用 BroadcastReceiver
进行通知。
一切都很好,直到我添加 .addAction
。
默认需要PendingIntent
,我做了一个PendingIntent
。
但问题是这样的;当我添加 .addAction
时,它显示为
Incompatiable types.
Required : android.app.Notification
Found : android.app.Notification.Builder
代码在没有 .addAction
和 PendingIntent
的情况下工作得很好。
可能是什么问题?
这是我的代码,
BroadcastReceiver
,WifiService.java
Intent intent = new Intent(mcontext, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pIntent = PendingIntent.getActivity(mcontext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification noti = new Notification.Builder(mcontext) .setContentTitle("Welcome home!") .setContentText("You have a to-do; " + hometodo) .setSmallIcon(R.drawable.home_light) .setLargeIcon(icon) .setLights(0xFFFFD800, 5000, 0) .addAction(R.drawable.archive_notification, "Mark as done", pIntent); //.addAction gets the error. .build(); NotificationManager notificationManager = (NotificationManager) mcontext.getSystemService(mcontext.NOTIFICATION_SERVICE); notificationManager.notify(0, noti);
使用 NotificationCompat
设置 .addAction(...)
。
action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later.