Question:
The Android application does not ask for the permissions specified in the manifest during installation. I had a service for notifications there. And it doesn't work at all. In the manifest, everything is spelled out according to all the canons, but when I install it, it writes
no special permissions are required for this application.
even though there are a lot of uses-permission
. How can you make it ask when installing?
Answer:
Starting with API 23
(Android 6.0), " dangerous " permissions must be requested at runtime .
Check if you have the required permissions:
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
!= PackageManager.PERMISSION_GRANTED) {
// Разрешение не получено
}
Requesting permission:
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
We process the result of obtaining permits:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
// При отмене предоставления разрешений, этот массив пуст
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Разрешение получено
} else {
// Пользователь отказался предоставлять разрешение
}
return;
}
// Обрабатываем другие разрешения
}
}