Android M Request Multiple permission at a single time

血红的双手。 提交于 2019-12-20 03:16:06

问题


Hi i am updating my application jaffna Temples . so that it can support Android M devices (v 6.0 and above).

Is there a way i can request multiple permission at a single time. eg: I want to get the permission to read phone state and location information at the same time.

Using this ways i can request permission one by one. But i want to rest both permission at once at the start of the application.

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},
                    PERMISSIONS_REQUEST_READ_PHONE_STATE);
        } else {
            setPhoneDetails();
        }
    }

Please give me some suggestions. Tnx.


回答1:


Is there a way i can request multiple permission at a single time

Put more than one permission in the String[] that you are passing to requestPermissions().

For example, in this sample project, I define collections of permissions statically, such as:

  private static final String[] PERMS_TAKE_PICTURE={
    CAMERA,
    WRITE_EXTERNAL_STORAGE
  };

so that I can request those permissions later:

ActivityCompat.requestPermissions(this, PERMS_TAKE_PICTURE,
    RESULT_PERMS_INITIAL);


来源:https://stackoverflow.com/questions/36385161/android-m-request-multiple-permission-at-a-single-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!