【发布时间】:2017-09-02 17:33:18
【问题描述】:
我在粘性通知中有一个自定义按钮。
我曾经附加一个PendingIntent 来接收按钮点击:
Intent intent = new Intent();
intent.setAction("com.example.app.intent.action.BUTTON_CLICK");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 2000, intent, PendingIntent.FLAG_UPDATE_CURRENT);
contentViewExpanded.setOnClickPendingIntent(R.id.button, pendingIntent);
当我在 Oreo 上运行此代码时,我在 logcat 中得到 BroadcastQueue: Background execution not allowed 并且没有收到按钮点击。
我用清单注册了接收器:
<receiver
android:name=".BroadcastReceiver.NotificationActionReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.example.app.intent.action.BUTTON_CLICK"/>
</intent-filter>
</receiver>
我也尝试在我的代码中注册接收器:
NotificationActionReceiver mMyBroadcastReceiver = new NotificationActionReceiver();
IntentFilter filter = new IntentFilter("com.example.app.intent.action.BUTTON_CLICK");
mContext.registerReceiver(mMyBroadcastReceiver, filter);
这有效,但仅当应用对用户可见时。
感谢您的帮助
【问题讨论】:
-
@UmarHussain 我知道它已经改变了:我已经阅读了文档但没有运气。
-
Ph 好吧,其实我还没有在 oreo 中实现广播,所以不知道为什么会出现这个问题
标签: android broadcastreceiver android-notifications background-process android-8.0-oreo