Prerak Sola Prerak Sola - 4 months ago 21
Android Question

Android N permission Issue

I have Android N Developer preview version on my testing device, and I am asking for runtime permission during the app launch.

But unfortunately, the app doesn't display the alert dialog to grant the permissions. I am using the below code:

Launcher Activity

public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

if(checkPermissions()) {
renderView();
}
}

private boolean checkPermissions() {

int permissionWriteStorage = ContextCompat.checkSelfPermission(this, Manifest.permission_group.STORAGE);
int permissionPhoneState = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);

Log.i("permission",(permissionWriteStorage == PackageManager.PERMISSION_GRANTED) + "");
//This prints false

List<String> listPermissionsNeeded = new ArrayList<>();
if (permissionWriteStorage != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission_group.STORAGE);
}
if (permissionPhoneState != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.READ_PHONE_STATE);
}

if (!listPermissionsNeeded.isEmpty()) {
Log.i("permission", "in if");
//I get this in the logs

ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}
}


build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
applicationId 'com.***.***'
minSdkVersion 16
targetSdkVersion 24
}
}


EDIT: Solution (1/2)

By changing the build tools version to
24.0.1
I am getting the alert for
READ_PHONE_STATE
permission but not for the permission group
STORAGE
.
Do we need to ask separately for each permission of a permission group?

EDIT 2: Solution (2/2)

I managed to solve it by replacing
Manifest.permission_group.STORAGE
with
Manifest.permission.WRITE_EXTERNAL_STORAGE
. As per the docs, you just need confirmation for one dangerous permission for the whole group.


The user only needs to grant permission once for each permission group. If your app requests any other permissions in that group (that are listed in your app manifest), the system automatically grants them.

Answer

i'm not sure but changed build tools version

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId 'com.***.***'
    minSdkVersion 16
    targetSdkVersion 24
}
Comments