I am struggling with this problem when the application goes to run on the mobile phone HUAWEI ALE - 21 Android 6.0 API 23 . My application collapses and I take back those e
You need to check permission and request permission as below:
Code example:
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
"com.huawei.android.launcher.permission.WRITE_SETTINGS")
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
"com.huawei.android.launcher.permission.WRITE_SETTINGS")) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed; request the permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{"com.huawei.android.launcher.permission.WRITE_SETTINGS"},
MY_PERMISSIONS_REQUEST_WRITE_SETTINGS);
// MY_PERMISSIONS_REQUEST_WRITE_SETTINGS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
} else {
// Permission has already been granted
}
For more details, see: https://developer.android.com/training/permissions/requesting