如何在android中一次请求多个权限?

时间:2017-10-27 13:27:51

标签: android

如何立即在android中请求多个权限。我使用下面的代码,但它一次要求一个权限,当我关闭应用程序并重新启动它然后它要求下一个权限。如何摆脱这个问题,,,,,,,任何帮助

提前完成 快乐编码:)

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

0 个答案:

没有答案