Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to ask for multiple permission at once in android?

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 1.78k
    Answer it

    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;
    }

     

 2 Answer(s)

  •         if ((ContextCompat.checkSelfPermission(this,

    Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)||

     

    (ContextCompat.checkSelfPermission(this,

    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)||

    (ContextCompat.checkSelfPermission(this,

    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED))

    {

    ActivityCompat.requestPermissions(this,

    new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.CALL_PHONE,Manifest.permission.READ_CONTACTS,Manifest.permission.WRITE_CONTACTS,Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE},1);

    }

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: