我在粘性通知中有一个自定义按钮.
我曾经附加一个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);
Run Code Online (Sandbox Code Playgroud)
当我在奥利奥上运行此代码时,我进入BroadcastQueue: Background execution not allowedlogcat并且没有收到按钮点击.
我用清单注册了接收器:
<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>
Run Code Online (Sandbox Code Playgroud)
我也尝试在我的代码中注册接收器:
NotificationActionReceiver mMyBroadcastReceiver = new NotificationActionReceiver();
IntentFilter filter = new IntentFilter("com.example.app.intent.action.BUTTON_CLICK");
mContext.registerReceiver(mMyBroadcastReceiver, filter);
Run Code Online (Sandbox Code Playgroud)
这只适用于应用程序对用户可见的情况.
感谢帮助
android background-process broadcastreceiver android-notifications android-8.0-oreo
android ×1