Fresco does not work after grant permission
- Dominant language
- Kotlin
- Stars
- 17.2k
- Forks
- 3.7k
- PR merge metrics
- No merged PRs in 30d
Description
I have a problem when using Fresco to show an external uri
Open app and enter an activity without READ_STORAGE_PERMISSION
Ask for that permission with ActivityCompat
After get the result (the permission granted), I collect all images from external content uri and get the uris like this: content://media/external/images/media/125
but fresco give error:
AbstractDraweeController: controller e65ea68 1: final_failed @ onFailure: failure: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20180717_182941.jpg (Permission denied)
Force close app and open again (now app has permission), the image I collected display normally
* Fresco version: 1.9.0 on gradle
* Platform version: Android target 28, emulator
[SelectImageActivity.kt.zip](https://github.com/facebook/fresco/files/2207889/SelectImageActivity.kt.zip)
```
package com.zody
import android.Manifest
import android.content.ContentUris
import android.content.pm.PackageManager
import android.os.Bundle
import android.provider.MediaStore
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.facebook.common.logging.FLog
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.drawee.view.SimpleDraweeView
import timber.log.Timber
/**
* Created by vinhnguyen.it.vn on 2018, July 19
*/
class SelectImageActivity : AppCompatActivity() {
private val imageView: SimpleDraweeView by lazy { SimpleDraweeView(this) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Fresco.initialize(this.applicationContext)
FLog.setMinimumLoggingLevel(FLog.VERBOSE)
setContentView(imageView)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), 1)
} else {
queryImageAndShow()
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
queryImageAndShow()
}
}
private fun queryImageAndShow() {
val what = arrayOf(MediaStore.Images.Media._ID)
val cursor = MediaStore.Images.Media.query(contentResolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
what, null, null, null)
if (cursor.moveToFirst()) {
val id = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media._ID))
val uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)
Timber.tag("Fresco").d("The uri we get is $uri")
imageView.setImageURI(uri, null)
}
cursor.close()
}
//There are the logcat:
//Fresco: The uri we get is content://media/external/images/media/103
//unknown:AbstractDraweeController: controller 68ea53f 0: final_failed @ onFailure: failure: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/IMG_20180717_115110.jpg (Permission denied)
//Note:
//Permission not granted when launching
//Force close app and launch again (now the app have permission, it works normally)
}
```
Contributor guide
Assessment
This issue has not been assessed yet.