Removable SD Card access, or, Internal SD folder access

Since updating to 4.3 and using Android 12 device I can no longer access the folder path I used with 4.01 and Android 4 which was a folder at storage/emulated/0/…
I now get a message that the folder is not accessible and presume it is due to security creep by Android. I can find no information that permits me to use a folder that is ‘public?’ on my own device for my own purposes.
I have been unable to produce an APK for install (thus presumably providing a folder for its use). I simply connect the device and run on the device to leave a permanently useable app. I did set the read and write permissions to EXTERNAL_STORAGE.
Can somebody please help with a path to preferably the removable SD. It is a Samsung 6 Lite tablet.

@enonod

Yes this is Google’s doing … new security requirements. To access storage you now have to use the Storage Access Framework… shouldn’t impact installation of an apk though??, just storage access once the app is running.

This discussion has some code is an example of how to load and save a file …

Thank you bigboss97. Before I get heavily into this, being an amateur, do I need to produce an APK to proceed?
I ask because I have so far been unable to produce one and so I just run the game from the Mac onto the tablet. It must be stored somewhere but presumably because it is not an APK it does not set up a com.xxx under Android storage.
If you answer is yes then can you possibly first get me to producing an APK. I have followed several solutions but my menus do not seem to have the same as tutorials.
Is there a simple way? It is very simple for java mode in windows.
Thank you for whatever you can help with.
Edit: I am happy not to use the removable SD if I produce an APK and use storage internal.

@enonod

We’re you able to produce an apk before your upgrade?

Running direct to your tablet is fine … this must be producing an apk otherwise it wouldn’t install, but it’s much harder to see the folder where your com.xxx etc is stored now. I’ve tried to find it on my devices and haven’t been able to locate it either … it’s hidden from view.

I’m not an expert but my understanding is that an app can access the hidden internal storage that Android allocates to it … so you can still access you data folder etc but accessing any other storage needs the storage access framework. It all looks a bit scary but try to get your head round it as it’s the only way !

@bigboss97 Thanks for your continued input.
No I have never been able to produce an APK so that I could install. If I could my problem would go away because I could store my game data in its proper place.
I have tried to export to APK but can never find it where others have said it should be.
I have actually fought shy of the two options that appear to produce for Play Store, because I only require it for myself.
Perhaps you can help with that?

@enonod

No problem… I’ll try to help … I’ll likely learn things useful to me too :wink:

To go with my previous code snippet … have a read of this …

https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://developer.android.com/training/data-storage/shared/documents-files&ved=2ahUKEwi86s-4h96GAxWbV0EAHe_TD1kQFnoECBcQAQ&usg=AOvVaw02D3_m1S3o9RjXcbXsdTWC

It’s initially confusing but is really useful once you understand.

Re your APK generation I’ll have a play. It’s a while since I used processing as I moved to Android Studio, although if it’s only for yourself, just running direct from you computer is probably good enough?

PS I’m @shedMusic

@shedMusic Thanks again. Started reading as suggested. The first thing I noted was app user intervention in selecting folder. In my case this is a game and the only data stored/retrieved is the game scores and array data, the user is not expected to be aware of that or be bothered by it. That transparency is already built in with the display of same info.
If I can get to apk production and install, I could simply use the proper storage for the app because the user doesn’t need to know. That appears to me to be the simplest solution compared to having to recode a lot.
I think that would be the first attempt at solution. The other looks more complicated and for when somebody wants to choose the location and possibly even access other locations.
If you can help with APK I should like that first.
Thanks
EDIT: Read the rest and it keeps describing what to do and then saying not above version 11 while I am using Android 12. Perhaps the first approach might be finding out how to access the apps own folder, even though I cannot see it. Is there standard code for that?

@enonod

Yes ok … that’s sensible!

As a first step then, I’d just use basic Processing functions like saveBytes(), loadBytes() etc as the data is saved in the data folder with nothing else to do?

I’ll get back about APK generation but for just your use there’s no need? The app is installed on your tablet by hitting the Processing run button as otherwise tha app wouldn’t work.

1 Like

@shedMusic I just crossed in the post!
EDIT: Read the rest of what you pointed to and it keeps describing what to do but then saying not above version 11 while I am using Android 12. Perhaps the first approach might be finding out how to access the apps own folder, even though I cannot see it after running the sketch onto the tablet. Is there standard code for that?
I was using dirName = Environment.getExternalStorageDirectory().getAbsolutePath() + xxx but of course that is not accessible in Android 12
Off duty 'til tomorrow morning.
Morning:
My program does saveBytes() etc. but it saves to the path obtained above. I don’t know the path to the sketch’s own folder, or how to obtain it. If it’s easy then problem solved.

@shedMusic You gave me the clue, ‘data folder’. I had used SD card on Android 4 so I could look at it easily with debug. I totally forgot that location and went down the ‘rabbit hole’ of trying to correct the SD Card location for Android 12, which cannot be used easily. I forgot.
Your last post triggered the memory so now I can use dataPath() as normal.
Sorry for dragging you down the ‘rabbit hole’ and thank you so much for your memory trigger.

@enonod

No problem … I wanted to think this through anyway👍

For info … you can use

getContext().getFilesDir() and
getContext().getExternalFilesDir()

to get the OS allocated storage locations, but both get deleted when an app is uninstalled.

SAF give a durable storage … data kept and can be moved to a new device etc …

@enonod

APK build works for me … but must give a package name in the manifest and provide a set of icons in the sketch folder.

@shedMusic. That all makes sense now and thank you once again.
Have a nice Father’s Day if you are one.

@shedMusic If you are still available I have not made the progress I hoped and maybe you can assist a little further.
Instead of trying to modify my program to use Android 12 instead of Android 4, I might be better simply creating a simple sketch to create a text file and then reading it back and appending new text and saving. Is it possible to show a working version for me to then work on please? I have tried stuff from all over the internet but none works.
I have detected a file is present using sketchPath() but I cannot open it as I did before with the simple code I used.

I used to generate APK with v3. I remember that I got errors on v4.
It’s not a problem of reading/writing files. But those files are hidden from other apps. I wrote the file to SD card because I want it to be edited by 3rd party editor.

To be honest, I can’t remember the process of generating APK. I haven’t done Android app for a while. I simply can’t keep up with Android changes :frowning_face:

Sorry, my mistake. I think I didn’t generate the APK. But compile and run the sketch. Then it will pop up on my phone. As I said, it’s history :grin:

I’m trying my sketch on v4. This time no Android related errors. But my Android USB debugging connection is not detected.

@enonod
I’ll try to get something posted later today

@shedMusic Thanks for coming back. I just tried an earlier incomplete version of my program and it reads the text file perfectly. At present it looks to be the use of sketchPath and dataPath. I am simply using xxx = loadStrings(sketchPath(“xxx.txt”));
In both cases I am using Processing 4.3 Android Mode, the txt file is in Data folder and I am sending to the same tablet Samsung S6 Lite Android 12. I have no path set in either.
The one that does not read the file gives the message 'Read Only file system".
The one that does read does not give that message.
Neither have READ_ONLY_STORAGE set. So why the difference.
If I set that on the one that does not read the file, it does not crash but does not read.
If I then leave it set and change the code to dataPath from sketchPath it crashes with the same Read Only message. So it must need sketchPath.
The one that works can use either dataPath or sketchPath.
Baffled because I cannot see the difference. Do these clues suggest where the problem lay?
EDIT:
I have cracked it and the clue is 3rd line down. It should not have sketchPath(“xxx.txt”) simply loadStrings(“xxx.txt”) plus the READ and WRITE permissions are not needed.
Also; state = Environment.getExternalStorageState(); and
dirName = Environment.getExternalStorageDirectory().getAbsolutePath()+xxx.
Not needed at all.
Thanks for your help and forbearance.

@enonod

I was just about to post the exact same answer … glad you found out what you need!