Is listFiles Broken on Android 13?

28 Views Asked by At

So, my question is very similar to this post

And others.

I also tried to add the necessary permissions to the MainActivity.xml

But, it seems I have to put in more gymnastics to my application to make this 'read-only' operation work?

Here's the salient Kotlin routine: the commented line is what isn't working.

    fun build_snapshot_override_list() : Array<String>
    {
        //val sideload_dir = File(Environment.getExternalStorageDirectory().path+"/snapshot-images")
        val sideload_dir = File("/data/local/tmp/snapshot-images")
        val files = sideload_dir.listFiles()
        var sideload_images = arrayOf<String>()

        if(files != null) {
            Log.d(TAG, "found ${files.size} entries in ${sideload_dir.path}")
            files.forEach { f -> sideload_images += f.path }
            files.forEach { F -> Log.d(TAG, "File: ${F.path}") }
        }

        return sideload_images
    }

But, I can list files just fine under /data/local/tmp/snapshot-images/

Anyone have an idea on how to make this work, in a more succinct way than what Android is recommending (asking for "permssion intents"?

Thanks, Charles.

The only place listFiles() seems to work, is /data/local/tmp (not desirable).

0

There are 0 best solutions below