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
    • 1
    • 0
    • 0
    • 0
    • 14
    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;
    }

     

 1 Answer(s)

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: