Reputation: 1972
I'm having a little trouble with Android 6 dangerous permissions feature, where the user has to explicitly grant some permissions. In my case, I request for an array of permissions with the following code:
public class SplashScreenActivity extends BaseActivity implements
RefreshClientOptionsTask.IRefreshClientOptionsListener {
private static final String [] DANGEROUS_PERMISSIONS = {permission.READ_PHONE_STATE,
permission.READ_SMS,
permission.ACCESS_FINE_LOCATION,
permission.CALL_PHONE,
permission.WRITE_EXTERNAL_STORAGE,
permission.READ_EXTERNAL_STORAGE,
permission.CAMERA
};
private void initPermissions() {
List<String> missingPermissions = new ArrayList<String>();
for(String permission : DANGEROUS_PERMISSIONS) {
if(ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
missingPermissions.add(permission);
}
}
if (missingPermissions.size() > 0) {
String [] permissions = new String[missingPermissions.size()];
ActivityCompat.requestPermissions(
this,
missingPermissions.toArray(permissions),
1);
} else {
// we have all permissions, move on
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
for(int grantResult : grantResults) {
// handle denied permissions
}
}
}
When this code executes I'm presented with four permission request dialogs. After I press 'allow' in every dialog onRequestPermissionsResult
is executed and grantResults
argument contains all zeroes (PERMISSION_GRANTED
) except for READ_SMS
permission - it's equal to -1 (PERMISSION_DENIED
). What's happening and how should I handle this situation?
I'm testing on a physical device running Android 6.0.
Upvotes: 0
Views: 2626
Reputation: 4477
Android changed permission accept in Latest 23 API level,In This Process Some permission that will be automatically granted at install time those are specify in Manifest ,Remaining Permission's Are Accept's in RunTime , Because So many bad guys trying to collect user's personal data through this security weakness So Android Change's to Runtime Permission
For More About Runtime Permission Check The Below Link
Everything every Android Developer must know about new Android's Runtime Permission
Upvotes: 1
Reputation: 39181
When dealing with Marshmallow's new permissions model, any required permission must be listed in the manifest, in addition to requesting the dangerous permissions at runtime.
In this case, it seems that you effectively did not have the READ_SMS
permission in the manifest, which is why it was denied at runtime.
Upvotes: 3