0

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 :)

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;
}
danilonet
  • 1,757
  • 16
  • 33
  • 1
    check this **[How to check the multiple permission at single request in Android M?](https://stackoverflow.com/questions/34040355/how-to-check-the-multiple-permission-at-single-request-in-android-m)** – AskNilesh Oct 27 '17 at 13:28
  • there are many libraries available for managing permissions. You can use them to prevent the hassle. – Vivek Mishra Oct 27 '17 at 13:29
  • I have read and applied all available code related my query, But those are not working in my app. Every time I'm facing the above-discussed problem. – Jhalani Oct 28 '17 at 06:45

0 Answers0