Unable to grant permission to my android app to read a text file on android 13

557 Views Asked by At

i am implement an android application in java and everything was working perfectly until i install it on an android 13 version . Since then , i can't grant the permission to read file ( specially text file ) . How could i solve it ?

1

There are 1 best solutions below

0
MaciekŻelek On

I also had a problem with the lack of access to ExternalStorage for text files from my specified path which was like this:

/storage/emulated/0/ dictfiles/

Until SKD<=12, I was setting my path as :

private final static String PATH = "/dictfiles/";
String stringPathDirectory = Environment.getExternalStorageDirectory().getAbsolutePath() + PATH;

up to version sdk=12 everything worked without a problem and with sdk=13 it stopped working – permission denied.

MY TEMPORARY SOLUTION

According to the new approach with SDK=13, we can do access to:

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"  />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"  />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"  />

So I entered into the manifest file what the new approach requires and I still couldn't read from my specified path. Looking at the above permission, we get access to few directories among others PICTURES.

So put my directory with text files into the PICTURES directory.

I changed the access path to my directory and files to:

String stringPathDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ PATH;

So now my directory path looks like /storage/emulated/0/Pictures/dictfiles

But my snippet code:

File[] files = directory.listFiles();

which scanned the directory for files, still couldn't find my text files. I think that because Android by default requires graphic files in the Pictures directory and it did, it found .jpg .png .gif but my dicfiles directory with text files was missing. So in all my text files I added .jgp extension to my text files and now the code doesn't skip them.

Until I find another solution, this is how I solve it, but I haven't found another solution on the Internet and I've been looking for a long time.