Reputation: 795
Why this code works:
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
666);
## In the manifest
<uses-permission android:name="android.permission.READ_CONTACTS" />
and this code doesn't work:
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE},
666);
## In the manifest
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
The first snippet starts the request permission activity asking for read contacts permissions. The last snippet doesn't show the activity and in the logs there is this message:
10-16 12:19:48.061 1138-3635/? I/ActivityManager: START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller cmp=com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity (has extras)} from uid 10147 on display 0
So, what I'm supposed to do to ask notifications permissions? Target API is v24 and the minimum sdk version is 23.
Upvotes: 0
Views: 11785
Reputation: 27211
Here you can see the list of permissions you have to ask https://developer.android.com/guide/topics/security/permissions.html
READ_CALENDAR, WRITE_CALENDAR
CAMERA
READ_CONTACTS, WRITE_CONTACTS, GET_ACCOUNTS
ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, RECORD_AUDIO
READ_PHONE_STATE, CALL_PHONE, READ_CALL_LOG, WRITE_CALL_LOG, ADD_VOICEMAIL USE_SIP, PROCESS_OUTGOING_CALLS
BODY_SENSORS
SEND_SMS, RECEIVE_SMS, READ_SMS, RECEIVE_WAP_PUSH, RECEIVE_MMS
READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE
Upvotes: 0
Reputation: 6704
From documentation
BIND_NOTIFICATION_LISTENER_SERVICE
String BIND_NOTIFICATION_LISTENER_SERVICE
Must be required by an NotificationListenerService, to ensure that only the system can bind to it.
Which means it doesn't necessarily need to grant by user at runtime. Rather, it needs to be declared in manifest.xml under a NotificationListenerService. Something like this,
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Upvotes: 1
Reputation: 4513
well, run time permissions are asked only for dangerous permissions, since notification service is not a dangerous permission you need not ask it. here is the list of all dangerous and not dangerous permissions.
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
p.s. no matter permission is dangerous or normal, both must be declared in manifest, only difference is in run time requests.
Upvotes: 3