I am trying to grant permissions on Android Marshmallow but it still does not work. The code that I used is this:
private boolean checkAndRequestPermissions() {
int pocatioPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_SETTINGS);
int permi = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
List<String> listPermissionsNeeded = new ArrayList<>();
if (permi != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (pocatioPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.WRITE_SETTINGS);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}
But in the console I still see this error:
was not granted this permission: android.permission.WRITE_SETTINGS
Thank you very much for the answers, but I still can not get it to work. I have put the permissions on the manifest and now I have added the Settings.System.canWrite () but it still gives me the same error, the strange thing is that when I start the app the windows should appear to grant the permissions and it only appears for the permission WRITE_EXTERNAL_STORAGE but for the WRITE_SETTINGS it does not show me any little windows to grant permissions.