MediaStore.CreateWriteRequest(ContentResolver, ICollection<Uri>) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 PendingIntent 一個會提示使用者授權你應用程式撰寫所需媒體項目的應用程式。
[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
參數
- resolver
- ContentResolver
曾經與 MediaStore#AUTHORITY.
通常這個值為 Context#getContentResolver(),但如果你需要更明確的生命週期控制,你可以取得 並 ContentProviderClient 用 ContentResolver#wrap(ContentProviderClient)包裝。
- uris
- ICollection<Uri>
此請求中應包含的媒體項目。 每個項目必須由 主機,MediaStore#AUTHORITY且必須引用特定媒體項目。BaseColumns#_ID
傳回
- 屬性
備註
建立 PendingIntent 一個會提示使用者授權你應用程式撰寫所需媒體項目的應用程式。
此呼叫僅產生提示請求;要顯示提示詞,請用 Activity#startIntentSenderForResultPendingIntent#getIntentSender()。 接著你可以透過測試 Activity#RESULT_OK 在 Activity#onActivityResult中 來判斷使用者是否批准了你的請求。 所請求的操作在該活動結果交付前已完全完成。
透過此機制授予的權限會綁定於請求權限的生命週期 Activity 。 如果你需要保留背景操作的長期存取權,可以將項目放入 ClipData or Intent 中,然後再傳給 Context#startService 或 android.app.job.JobInfo.Builder#setClipData。 務必包含你想保留的相關存取模式,例如 Intent#FLAG_GRANT_WRITE_URI_PERMISSION。
顯示的提示會反映你所請求的所有媒體項目,包括你已經擁有寫入權限的項目。 如果你想在請求存取前確定是否已經持有寫入權限,請使用 Context#checkUriPermission(Uri, int, int, int) 。Intent#FLAG_GRANT_WRITE_URI_PERMISSION
出於安全與效能考量,此方法不支援 Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION 或 Intent#FLAG_GRANT_PREFIX_URI_PERMISSION。
透過此請求所授予的寫入權限是通用的,取得後你可以直接 ContentResolver#update 寫欄位如 MediaColumns#IS_FAVORITE、 MediaColumns#IS_TRASHED、 ContentResolver#delete或 。
注意:如果你的應用程式目標達到 android.os.Build.VERSION_CODES#BAKLAVA 以上,每次請求最多只能寄送2000 尿路幣。 嘗試傳送超過 2000 個 URIS,將導致 java.lang.IllegalArgumentException。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。