Checking the permission above marshmallow (API 23)
Android Marshmallow completely different from previous version of lollipop. Because they need to check and request the permissions in run time. If permission requires to change, need to apply immediately else can't access those features.
For more details refer the developer site
Here I give some code, just try it.
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
int hasLocationPermission = checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION);
int hasSMSPermission = checkSelfPermission(android.Manifest.permission.SEND_SMS);
int hasAccessLocation = checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION);
int hasGetAccounts = checkSelfPermission(android.Manifest.permission.GET_ACCOUNTS);
int hasInternet = checkSelfPermission(android.Manifest.permission.INTERNET);
int hasAccessNetwork = checkSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE);
int hasAccounts = checkSelfPermission(android.Manifest.permission.ACCOUNT_MANAGER);
int hasCamera = checkSelfPermission(android.Manifest.permission.CAMERA);
int hasVibrate = checkSelfPermission(android.Manifest.permission.VIBRATE);
int hasReadContacts = checkSelfPermission(android.Manifest.permission.READ_CONTACTS);
int hasWriteContacts = checkSelfPermission(android.Manifest.permission.WRITE_CONTACTS);
int hasReadStorage = checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE);
int hasWriteStorage = checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
int hasWakeLock = checkSelfPermission(android.Manifest.permission.WAKE_LOCK);
int hasChangeNetwork = checkSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE);
int callphone = checkSelfPermission(android.Manifest.permission.CALL_PHONE);
List<String> permissions = new ArrayList<String>();
if (hasCamera != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.CAMERA);
}
if (hasVibrate != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.VIBRATE);
}
if (hasReadContacts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.READ_CONTACTS);
}
if (hasReadStorage != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (hasLocationPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION);
}
if (hasLocationPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION);
}
if (hasAccessLocation != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (hasGetAccounts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.GET_ACCOUNTS);
}
if (hasInternet != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.INTERNET);
}
if (hasAccessNetwork != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_NETWORK_STATE);
}
if (hasAccounts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCOUNT_MANAGER);
}
if (hasChangeNetwork != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.CHANGE_NETWORK_STATE);
}
if (hasWakeLock != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.WAKE_LOCK);
}
if (hasWriteStorage != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (hasWriteContacts != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.WRITE_CONTACTS);
}
if (!permissions.isEmpty()) {
requestPermissions(permissions.toArray(new String[permissions.size()]), REQUEST_CODE_SOME_FEATURES_PERMISSIONS);
}
}
For more details refer the developer site
Here I give some code, just try it.
if (currentapiVersion >= android.os.Build.VERSION_CODES.M) {
int hasLocationPermission = checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION);
int hasSMSPermission = checkSelfPermission(android.Manifest.permission.SEND_SMS);
int hasAccessLocation = checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION);
int hasGetAccounts = checkSelfPermission(android.Manifest.permission.GET_ACCOUNTS);
int hasInternet = checkSelfPermission(android.Manifest.permission.INTERNET);
int hasAccessNetwork = checkSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE);
int hasAccounts = checkSelfPermission(android.Manifest.permission.ACCOUNT_MANAGER);
int hasCamera = checkSelfPermission(android.Manifest.permission.CAMERA);
int hasVibrate = checkSelfPermission(android.Manifest.permission.VIBRATE);
int hasReadContacts = checkSelfPermission(android.Manifest.permission.READ_CONTACTS);
int hasWriteContacts = checkSelfPermission(android.Manifest.permission.WRITE_CONTACTS);
int hasReadStorage = checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE);
int hasWriteStorage = checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
int hasWakeLock = checkSelfPermission(android.Manifest.permission.WAKE_LOCK);
int hasChangeNetwork = checkSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE);
int callphone = checkSelfPermission(android.Manifest.permission.CALL_PHONE);
List<String> permissions = new ArrayList<String>();
if (hasCamera != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.CAMERA);
}
if (hasVibrate != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.VIBRATE);
}
if (hasReadContacts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.READ_CONTACTS);
}
if (hasReadStorage != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (hasLocationPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION);
}
if (hasLocationPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION);
}
if (hasAccessLocation != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_COARSE_LOCATION);
}
if (hasGetAccounts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.GET_ACCOUNTS);
}
if (hasInternet != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.INTERNET);
}
if (hasAccessNetwork != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCESS_NETWORK_STATE);
}
if (hasAccounts != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.ACCOUNT_MANAGER);
}
if (hasChangeNetwork != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.CHANGE_NETWORK_STATE);
}
if (hasWakeLock != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.WAKE_LOCK);
}
if (hasWriteStorage != PackageManager.PERMISSION_GRANTED) {
permissions.add(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (hasWriteContacts != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.WRITE_CONTACTS);
}
if (!permissions.isEmpty()) {
requestPermissions(permissions.toArray(new String[permissions.size()]), REQUEST_CODE_SOME_FEATURES_PERMISSIONS);
}
}
Comments