nibuen / SpaceAlertMissionGenerator

Mission Generator For Space Alert Board Game On Android
https://blog.iterary.com/
MIT License
15 stars 9 forks source link

Problems with external storage access in newer android APIs #48

Closed MarcusZuber closed 3 years ago

MarcusZuber commented 3 years ago

The app has issues with Android API 26 (Android 8.0) and newer with the access to the external storage.

In https://github.com/nibuen/SpaceAlertMissionGenerator/blob/678a6957a39e0c2ede494579f8ac0033ea6ea42b/app/src/main/java/com/boarbeard/io/ExternalMedia.java#L18 the dir.mkdirs() is executed, but no directory is created. Then opening the file for the readme.txt results in an exception.

W/System.err: java.io.FileNotFoundException: /storage/emulated/0/com.boarbeard/readme.txt: open failed: EACCES (Permission denied)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:496)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:235)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
W/System.err:     at com.boarbeard.io.ExternalMedia.init(ExternalMedia.java:34)
W/System.err:     at com.boarbeard.SpaceAlertApplication.onCreate(SpaceAlertApplication.java:19)
W/System.err:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1182)
W/System.err:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6460)
W/System.err:     at android.app.ActivityThread.access$1300(ActivityThread.java:219)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
W/System.err:     at android.os.Looper.loop(Looper.java:214)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
        at libcore.io.Linux.open(Native Method)
W/System.err:     at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
W/System.err:     at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:482)
        ... 14 more

When I create the /storage/emulated/0/com.boardbeard folder (and a sub-folder), the ExternalMedia::getMediaFolders() function does not detect the sub folders. Also writing the readme.txt does not work.

I manually set the storage permission of the app, but this also didn't change its behavior.

Unfortunately, I don't have any experience with the storage permission handling in android.