In Android 6.0, you need to explicitly ask the user for permissions. Just declaring it in the manifest is not enough.
This doc article is a great place to start exploring a new model, but I will give a brief summary.
Each time you perform an action that requires a "dangerous permission", you need to check if the permission is currently allowed, as the user can revoke it at any time.
This can be done using the checkSelfPermission method.
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { // We do not have this permission. Let ask the user }
You can request permission using the requestPermissions method as such
ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_PHONE_STATE}, PERMISSION_READ_STATE);
Where PERMISSION_READ_STATE is a constant integer that you defined to check the callback method later.
Then you will override onRequestPermissionsResult in your activity and see if permission has been granted. If that were the case, you could go ahead and take a dangerous action.
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSION_READ_STATE: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
source share