Share via


Activity.RequestPermissions Method

Definition

Overloads

RequestPermissions(String[], Int32)

Requests permissions to be granted to this application.

RequestPermissions(String[], Int32, Int32)

Requests permissions to be granted to this application.

RequestPermissions(String[], Int32)

Requests permissions to be granted to this application.

[Android.Runtime.Register("requestPermissions", "([Ljava/lang/String;I)V", "", ApiSince=23)]
public void RequestPermissions (string[] permissions, int requestCode);
[<Android.Runtime.Register("requestPermissions", "([Ljava/lang/String;I)V", "", ApiSince=23)>]
member this.RequestPermissions : string[] * int -> unit

Parameters

permissions
String[]

The requested permissions. Must be non-null and not empty.

requestCode
Int32

Application specific request code to match with a result reported to #onRequestPermissionsResult. Should be >= 0.

Attributes

Remarks

Requests permissions to be granted to this application. These permissions must be requested in your manifest, they should not be granted to your app, and they should have protection level android.content.pm.PermissionInfo#PROTECTION_DANGEROUS dangerous, regardless whether they are declared by the platform or a third-party app.

Normal permissions android.content.pm.PermissionInfo#PROTECTION_NORMAL are granted at install time if requested in the manifest. Signature permissions android.content.pm.PermissionInfo#PROTECTION_SIGNATURE are granted at install time if requested in the manifest and the signature of your app matches the signature of the app declaring the permissions.

Call #shouldShowRequestPermissionRationale before calling this API to check if the system recommends to show a rationale UI before asking for a permission.

If your app does not have the requested permissions the user will be presented with UI for accepting them. After the user has accepted or rejected the requested permissions you will receive a callback on #onRequestPermissionsResult reporting whether the permissions were granted or not.

Note that requesting a permission does not guarantee it will be granted and your app should be able to run without having this permission.

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to #onRequestPermissionsResult.

When checking whether you have a permission you should use #checkSelfPermission(String).

You cannot request a permission if your activity sets android.R.styleable#AndroidManifestActivity_noHistory noHistory to true because in this case the activity would not receive result callbacks including #onRequestPermissionsResult.

The permissions samples repo demonstrates how to use this method to request permissions at run time.

Java documentation for android.app.Activity.requestPermissions(java.lang.String[], int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

RequestPermissions(String[], Int32, Int32)

Requests permissions to be granted to this application.

[Android.Runtime.Register("requestPermissions", "([Ljava/lang/String;II)V", "", ApiSince=35)]
public void RequestPermissions (string[] permissions, int requestCode, int deviceId);
[<Android.Runtime.Register("requestPermissions", "([Ljava/lang/String;II)V", "", ApiSince=35)>]
member this.RequestPermissions : string[] * int * int -> unit

Parameters

permissions
String[]

The requested permissions. Must be non-null and not empty.

requestCode
Int32

Application specific request code to match with a result reported to #onRequestPermissionsResult. Should be >= 0.

deviceId
Int32

The app is requesting permissions for this device. The primary/physical device is assigned Context#DEVICE_ID_DEFAULT, and virtual devices are assigned unique device Ids.

Attributes

Remarks

Requests permissions to be granted to this application. These permissions must be requested in your manifest, they should not be granted to your app, and they should have protection level android.content.pm.PermissionInfo#PROTECTION_DANGEROUS dangerous, regardless whether they are declared by the platform or a third-party app.

Normal permissions android.content.pm.PermissionInfo#PROTECTION_NORMAL are granted at install time if requested in the manifest. Signature permissions android.content.pm.PermissionInfo#PROTECTION_SIGNATURE are granted at install time if requested in the manifest and the signature of your app matches the signature of the app declaring the permissions.

Call #shouldShowRequestPermissionRationale before calling this API to check if the system recommends to show a rationale UI before asking for a permission.

If your app does not have the requested permissions the user will be presented with UI for accepting them. After the user has accepted or rejected the requested permissions you will receive a callback on #onRequestPermissionsResult reporting whether the permissions were granted or not.

Note that requesting a permission does not guarantee it will be granted and your app should be able to run without having this permission.

This method may start an activity allowing the user to choose which permissions to grant and which to reject. Hence, you should be prepared that your activity may be paused and resumed. Further, granting some permissions may require a restart of you application. In such a case, the system will recreate the activity stack before delivering the result to #onRequestPermissionsResult.

When checking whether you have a permission you should use #checkSelfPermission(String).

You cannot request a permission if your activity sets android.R.styleable#AndroidManifestActivity_noHistory noHistory to true because in this case the activity would not receive result callbacks including #onRequestPermissionsResult.

The permissions samples repo demonstrates how to use this method to request permissions at run time.

Java documentation for android.app.Activity.requestPermissions(java.lang.String[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to