Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to ask for multiple permission in android at once. I m using below code but it is asking one permission at once, and when I close the app and relaunch it then it asks for next permission. How to get rid of this prob,,,,,,, any help

Thanx in advance
Happy Coding :)

What I have tried:

final int PERMISSION_ALL = 1;
final String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, Manifest.permission.READ_SMS,Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};

if(!hasPermissions(this, PERMISSIONS))
{
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}


public static boolean hasPermissions(Context context, String... permissions)
{
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission: permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900