Android 10 showing placeholder images even though requestLegacyExternalStorage = "true" ?
RageshAntony opened this issue · 3 comments
in Android 10 (ONE UI 2) , it's showing placeholder images even though requestLegacyExternalStorage = "true" ? I am using latest 2.2.5
My manifest
<application
android:name=".MyApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"
tools:ignore="AllowBackup,GoogleAppIndexingWarning"
tools:targetApi="m">
FilePicker call :
private fun pickImage() {
FilePickerBuilder.Companion.instance
.setMaxCount(10)
.setActivityTheme(R.style.AppTheme)
.setActivityTitle( getString(R.string.select_list_photos))
.enableImagePicker(true)
.enableVideoPicker(false)
.enableCameraSupport(true)
.showFolderView(false)
.showGifs(false)
.enableSelectAll(false)
.pickPhoto(this)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
FilePickerConst.REQUEST_CODE_PHOTO -> {
if (resultCode == Activity.RESULT_OK && data != null) {
val photoPaths = ArrayList<String>()
photoPaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_MEDIA))
val uriPaths = data.getParcelableArrayListExtra<Uri>(FilePickerConst.KEY_SELECTED_MEDIA)
validateFileSize(uriPaths)
}
}
}
}
Result
Please help me
thanks for your reply, I mean is when clicking on the icon "take photo" can't work on Android 11, Android 10 is ok.
Do you check on Android 11?
thanks for your reply, I mean is when clicking on the icon "take photo" can't work on Android 11, Android 10 is ok.
I check only in Android 10 . Not working in 10 but working in 9
hi all, I updated the lib, not using permission WRITE, it worked very well for me, some update in mine:
-
update dispatchTakePictureIntent function
fun dispatchTakePictureIntent(): Intent? {
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Ensure that there's a camera activity to handle the intent
if (Build.VERSION.SDK_INT >=29) {
filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker"))
val authority =
mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix)
photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
return takePictureIntent} else { if (takePictureIntent.resolveActivity(mContext.packageManager) != null) { // Create the File where the photo should go if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { filephoto = getImageFile(File(mContext.getFilesDir(), "filepicker")) val authority = mContext.packageName + mContext.getString(R.string.image_picker_provider_authority_suffix) photoURI = FileProvider.getUriForFile(mContext, authority, filephoto!!) takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI) } else { filephoto = getImageFile(File(mContext.getExternalCacheDir(), "filepicker")) takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filephoto)) } return takePictureIntent } } return null}
-
Because the app did not use permission WRITE so the photo after being taken will be stored in the internal memory.
-
Ater took you to have to call the function updateList again
-
In updateList function, you have to get photos in the internal memory
// get all photo in the internal memory
var arrayList = ArrayList(medias)
var file: File? = null
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
file = File(activity?.getExternalCacheDir(), "filepicker")
} else {
file = File(activity?.filesDir, "filepicker")
}
if (file != null && file.isDirectory!!) {
val children = file.listFiles()
Arrays.sort(children
) { o1, o2 -> java.lang.Long.compare(o1?.lastModified()!!, o2?.lastModified()!!) }
var index = 0
for (pathString in children) {
if (pathString.name.lastIndexOf(".jpg") > 0) {
if (!checkExist(arrayList, pathString.name)) {
val filePhoto = File(file.absolutePath + "/" + pathString.name)
if (filePhoto.length() > 0) {
val media = Media(
0,
getFileName(pathString.name),
Uri.fromFile(filePhoto),
1
)
arrayList.add(index, media)
}
}
}
}
mCurrentMedias = arrayList.toMutableList().toList()
}
here is the lib I updated, worked very well in my project
filepicker.zip
