无法使用Google照片通过ACTION_PICK删除图片

时间:2019-03-04 18:07:24

标签: android kotlin

使用Intent.ACTION PICK后,我需要从图库中删除图像。当我不使用谷歌照片选择图片时,我的代码可以正常工作。我已经在清单中要求获得许可。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这是我的乐趣所在:

fun selectPhoto(){
    if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED ){
        val intentOnResult = Intent(Intent.ACTION_OPEN_DOCUMENT)
        intentOnResult.type = "image/*"
        intentOnResult.flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
        startActivityForResult(intentOnResult,0)
    }else{
        requestStoragePermissions()
    }
}

onActivityResult:

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?){
    super.onActivityResult(requestCode, resultCode, intent)
    if (requestCode == 0 && resultCode == Activity.RESULT_OK && intent != null) {
        contentResolver.delete(intent.data!!,null,null)
        pictureloaded = true
    }

}

但是我得到这个错误:

java.lang.RuntimeException: Failure delivering result
ResultInfo{who=null, request=0, result=-1, data=Intent {
dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/32/ORIGINAL/NONE/656004224
flg=0x1 clip={text/uri-list
U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F32/ORIGINAL/NONE/656004224}
}} to activity
{com.maxiarce.habitstracker/com.maxiarce.habitstracker.AddHabitActivity}:
java.lang.SecurityException: Permission Denial: writing
com.google.android.apps.photos.contentprovider.impl.MediaContentProvider
uri
content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F32/ORIGINAL/NONE/656004224
from pid=9348, uid=10085 requires the provider be exported, or
grantUriPermission()

我找不到解决我问题的答案。对不起,如果我不清楚我是不是一个新人,谢谢!

0 个答案:

没有答案