Share via


Context.GrantUriPermission(String, Uri, ActivityFlags) Method

Definition

Grant permission to access a specific Uri to another package, regardless of whether that package has general permission to access the Uri's content provider.

[Android.Runtime.Register("grantUriPermission", "(Ljava/lang/String;Landroid/net/Uri;I)V", "GetGrantUriPermission_Ljava_lang_String_Landroid_net_Uri_IHandler")]
public abstract void GrantUriPermission (string? toPackage, Android.Net.Uri? uri, Android.Content.ActivityFlags modeFlags);
[<Android.Runtime.Register("grantUriPermission", "(Ljava/lang/String;Landroid/net/Uri;I)V", "GetGrantUriPermission_Ljava_lang_String_Landroid_net_Uri_IHandler")>]
abstract member GrantUriPermission : string * Android.Net.Uri * Android.Content.ActivityFlags -> unit

Parameters

toPackage
String

The package you would like to allow to access the Uri.

uri
Uri

The Uri you would like to grant access to.

modeFlags
ActivityFlags

The desired access modes.

Attributes

Remarks

Grant permission to access a specific Uri to another package, regardless of whether that package has general permission to access the Uri's content provider. This can be used to grant specific, temporary permissions, typically in response to user interaction (such as the user opening an attachment that you would like someone else to display).

Normally you should use Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION with the Intent being used to start an activity instead of this function directly. If you use this function directly, you should be sure to call #revokeUriPermission when the target should no longer be allowed to access it.

To succeed, the content provider owning the Uri must have set the android.R.styleable#AndroidManifestProvider_grantUriPermissions grantUriPermissions attribute in its manifest or included the android.R.styleable#AndroidManifestGrantUriPermission &lt;grant-uri-permissions&gt; tag.

Java documentation for android.content.Context.grantUriPermission(java.lang.String, android.net.Uri, 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

See also

  • <xref:Android.Content.Context.RevokeUriPermission(Android.Net.Uri%2c+Android.Content.ActivityFlags)>