Freigeben über


MediaStore.CreateWriteRequest(ContentResolver, ICollection<Uri>) Method

Definition

Create a PendingIntent that will prompt the user to grant your app write access for the requested media items.

[Android.Runtime.Register("createWriteRequest", "(Landroid/content/ContentResolver;Ljava/util/Collection;)Landroid/app/PendingIntent;", "", ApiSince=30)]
public static Android.App.PendingIntent CreateWriteRequest (Android.Content.ContentResolver resolver, System.Collections.Generic.ICollection<Android.Net.Uri> uris);
[<Android.Runtime.Register("createWriteRequest", "(Landroid/content/ContentResolver;Ljava/util/Collection;)Landroid/app/PendingIntent;", "", ApiSince=30)>]
static member CreateWriteRequest : Android.Content.ContentResolver * System.Collections.Generic.ICollection<Android.Net.Uri> -> Android.App.PendingIntent

Parameters

resolver
ContentResolver

Used to connect with MediaStore#AUTHORITY. Typically this value is Context#getContentResolver(), but if you need more explicit lifecycle controls, you can obtain a ContentProviderClient and wrap it using ContentResolver#wrap(ContentProviderClient).

uris
ICollection<Uri>

The set of media items to include in this request. Each item must be hosted by MediaStore#AUTHORITY and must reference a specific media item by BaseColumns#_ID.

Returns

Attributes

Remarks

Create a PendingIntent that will prompt the user to grant your app write access for the requested media items.

This call only generates the request for a prompt; to display the prompt, call Activity#startIntentSenderForResult with PendingIntent#getIntentSender(). You can then determine if the user granted your request by testing for Activity#RESULT_OK in Activity#onActivityResult. The requested operation will have completely finished before this activity result is delivered.

Permissions granted through this mechanism are tied to the lifecycle of the Activity that requests them. If you need to retain longer-term access for background actions, you can place items into a ClipData or Intent which can then be passed to Context#startService or android.app.job.JobInfo.Builder#setClipData. Be sure to include any relevant access modes you want to retain, such as Intent#FLAG_GRANT_WRITE_URI_PERMISSION.

The displayed prompt will reflect all the media items you're requesting, including those for which you already hold write access. If you want to determine if you already hold write access before requesting access, use Context#checkUriPermission(Uri, int, int, int) with Intent#FLAG_GRANT_WRITE_URI_PERMISSION.

For security and performance reasons this method does not support Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION or Intent#FLAG_GRANT_PREFIX_URI_PERMISSION.

The write access granted through this request is general-purpose, and once obtained you can directly ContentResolver#update columns like MediaColumns#IS_FAVORITE, MediaColumns#IS_TRASHED, or ContentResolver#delete.

Java documentation for android.provider.MediaStore.createWriteRequest(android.content.ContentResolver, java.util.Collection<android.net.Uri>).

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