Android Question Problem with File Permission

brodmuehler

Active Member
Licensed User
Longtime User
Dear All

I need some help please regarding storing a database file in internal storage of my Android S22. The background is that I have an app that uses an Sqlite database to store data and information. The app reads and writes from and to the database. The Sqlite file should be stored in a folder in the internal storage of my smartphone, not on an additional SD card, which the S22 doesn't have anyway.

I remember that Google changed the permission rules for reading and writing files to the internal storage, but I fail to figure out what I need to do to get the app working. The app worked nice on one of my older phones.

After I installed the app on my new phone and launched it I got the folling failure message:

Logger verbunden mit: samsung SM-S901B
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 575)
java.io.FileNotFoundException: /storage/emulated/0/gliderlog/gliderlog.sqlite: open failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
at b4a.gliderlog.main._activity_create(main.java:575)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at b4a.gliderlog.main.afterFirstLayout(main.java:105)
at b4a.gliderlog.main.access$000(main.java:17)
at b4a.gliderlog.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: android.system.ErrnoException: open failed: EPERM (Operation not permitted)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8611)
at libcore.io.IoBridge.open(IoBridge.java:560)
... 17 more
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 82 (Main)
java.io.FileNotFoundException: /storage/emulated/0/gliderlog/gliderlog.sqlite: open failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:342)
at b4a.gliderlog.main._activity_create(main.java:729)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.gliderlog.main.afterFirstLayout(main.java:105)
at b4a.gliderlog.main.access$000(main.java:17)
at b4a.gliderlog.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: android.system.ErrnoException: open failed: EPERM (Operation not permitted)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8611)
at libcore.io.IoBridge.open(IoBridge.java:560)
... 21 more
** Activity (main) Resume **

I zipped my project and attached it to this post. My phone is running with Android 12.

If there is anything else I should share please let me know.
I would highly appreciate if someone could help me.
Cheers
René
 

Attachments

File access is now very limited on Android and you will not be able to access that folder with normal file permissions.
 
Upvote 1
Dear All

thanks for pointing me in the right direction. I used the runtimepermissions and now it is working. The issue is closed

Cheers
René
 
Upvote 0
Back
Top