【发布时间】:2015-11-06 14:33:36
【问题描述】:
伙计们。
我已经调试了好几天了,但我找不到答案。
正如标题所说,我正在使用BroadcastReceiver 发出通知。
在我添加 .addAction 之前一切都很好。
默认需要PendingIntent,我创建了PendingIntent。
但问题是这样的;当我添加.addAction 时,它会这样说
Incompatiable types.
Required : android.app.Notification
Found : android.app.Notification.Builder
代码在没有.addAction 和PendingIntent 的情况下工作得很好。
可能是什么问题?
这是我的代码,
-
BroadcastReceiver,WifiService.javaIntent 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);
【问题讨论】:
-
.addAction(R.drawable.archive_notification, "Mark as done", pIntent);删除; -
我觉得自己很笨;(谢谢..
-
没有问题,欢迎您
标签: android android-intent android-notifications android-pendingintent