Reputation: 13747
My app needs to use a "READ_SMS" permission only. My problem is that on Android 6.0 When I need to use the new permission system it asks a "send and view SMS messages" from the user.
This is my code:
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_SMS}, READ_SMS_PERMISION_REQ);
What is going on? Thanks!
Upvotes: 5
Views: 3115
Reputation: 3011
I am use this
if (BuildUtil.isAndroidM()) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, PermissionUtil.sms(),
PermissionUtil.PERMISSION_SMS);
} else {
// TODO
}
} else {
// TODO
}
Upvotes: 0
Reputation: 1007296
What is going on?
It is working as expected.
While we request permissions via requestPermissions()
, the user accepts or denies permission groups. So, if your array had READ_SMS
and SEND_SMS
, despite having two permissions, the user would only have to accept one thing in the runtime permission dialog. Or, if you only had READ_SMS
here (and the user grants the permission), but then later called checkSelfPermission()
for SEND_SMS
, you would be told that you have it, as the user granted the whole SMS permission group.
The downside is that the permission groups often cover read and write permissions, so even if you only ask for read, the user is told that you might write.
My guess is that the objective was to keep the granularity of accept/deny decisions down. The fact that requestPermissions()
takes permissions, not groups, means that Google has the right to change its mind in future versions of Android, if this read vs. write issue becomes a problem for users or developers.
Upvotes: 7