Closed devfemibadmus closed 4 months ago
checking https://github.com/pg598595/ScopedStorageDemo i had similar code missing FLAG_GRANT_PERSISTABLE_URI_PERMISSION
i should be able to fix this with below code from above link
class OpenFolderActivity : AppCompatActivity() {
var fileList = ArrayList<DocumentFile>()
val adpater = FileViewAdpater(this, fileList)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_open_folder)
val layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)
rvTree.layoutManager = layoutManager
}
fun openDocTree(view: View) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
}
startActivityForResult(intent, OPEN_DIRECTORY_REQUEST_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == OPEN_DIRECTORY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
fileList.clear()
val directoryUri = data?.data ?: return
contentResolver.takePersistableUriPermission(
directoryUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION
)
loadDirectory(directoryUri)
}
}
fun loadDirectory(directoryUri: Uri) {
val documentsTree = DocumentFile.fromTreeUri(application, directoryUri) ?: return
val childDocuments = documentsTree.listFiles().asList()
for (i in 0 until childDocuments.size) {
Log.i("TAG", "${childDocuments[i].type}")
fileList.add(childDocuments[i])
}
rvTree.adapter = adpater
}
}
we using manage external storage instead of other well tried
action_open_document_tree
but didn't work https://github.com/devfemibadmus/whatsapp-status-saver#bug-flutter-fileimagevideo-not-working-with-android-action_open_document_tree-but-works-fine-in-kotlin so i skipped but now playstore reject app and said we should use smth else instead notmanage_external_storage
if you can fix this please feel free to fork this repo
below is other code i try with but seems i am not getting smth right, now i am leaving to contributors
@JohnMiltonHacks