【发布时间】:2016-08-24 23:54:14
【问题描述】:
创建通知:
PendingIntent pIntent = PendingIntent.getActivity(context, (int) taskId, intent, 0); intent.setAction(Utils.MARK_AS_DONE); PendingIntent pIntentMarkAsDone = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setTicker(ticker) .setContentTitle(title) .setContentText(description) .setSmallIcon(getAlarmIcon(type)) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher)) .setContentIntent(pIntent) .addAction(0, context.getString(R.string.mark_as_done), pIntentMarkAsDone); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int) taskId, notification);
我使用带有 getBroadcast 的挂起意图添加了添加。
接收者:
public class NotificationReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Log to check } }
这个类应该“接收”这个动作。我还添加了清单
清单:
<receiver android:name=".NotificationReceiver"> <intent-filter> <action android:name="<package_name>.MARK_AS_DONE"/> </intent-filter> </receiver>
好吧,onReceive 没有接收。我做错了什么?
【问题讨论】:
标签: android android-intent notifications broadcastreceiver action