I’m switching my target-sdk to 26 (android O) and due to the new background execution limits my broadcast receiver is not working anymore. According to Google documentation
Broadcasts that require a signature permission are exempted from this >restriction, since these broadcasts are only sent to apps that are signed >with the same certificate, not to all the apps on the device.
So I added a custom permission in my manifest. It’s working when I trigger the broadcast programmatically sendBroadcast(intent, “my.permission”) but I can’t find a way to make it work on an action button on a push notification because I don’t know how to specify the permission
notificationBuilder.addAction(drawable, "title", pendingIntent);
and my pendingIntent is setup like this
Intent acceptIntent = new Intent(); acceptIntent.setAction("android.intent.action.ACCEPT_ACTION"); pendingIntent = PendingIntent.getBroadcast(context,PENDING_INTENT_ACCEPT_REQUEST_CODE, acceptIntent, PendingIntent.FLAG_ONE_SHOT);
<permission android:name="my.permission" android:label="my_permission" android:protectionLevel="signature"/> <uses-permission android:name="my.permission"/> ... <receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:permission="my.permission" > <intent-filter> <action android:name="android.intent.action.ACCEPT_ACTION"/> </intent-filter> </receiver>
I cannot register the receiver programmatically in my activity, because it’s not linked to an activity. I cannot use a JobScheduler because it’s not relevant for my usecase. Do you have an idea?