Android Question Operation not permitted on SD card

Skipsy19

New Member
Hello all,

About 8 years ago I wrote an app with B4A no more compatible with recent android devices (of course !!).
So I have downloaded the B4A latest version, JDK ... And I am trying to compile it.

The first error message I get is the following :

** Activity (main) Create (first time) **
Error occurred on line: 235 (Main)
java.io.FileNotFoundException: /storage/emulated/0/saisie_bar.ini: open failed: EPERM (Operation not permitted)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileOutputStream.<init>(FileOutputStream.java:259)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at saisie.barv2.main.afterFirstLayout(main.java:105)
at saisie.barv2.main.access$000(main.java:17)
at saisie.barv2.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:257)
at android.os.Looper.loop(Looper.java:342)
at android.app.ActivityThread.main(ActivityThread.java:9634)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:619)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
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:579)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:579)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:9495)
at libcore.io.IoBridge.open(IoBridge.java:560)
... 19 more

I read that this is for new security reasons. I found out some tips from internet But no way to avoid this error.
Here is my manifest :

AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
SetApplicationAttribute(android:requestLegacyExternalStorage, "true")

Any idea would be welcome … ;-)

Thks a lot.
WW
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SetApplicationAttribute(android:requestLegacyExternalStorage, "true")
This will not work once targetSdkVersion >= 29

In most cases the solution is simple: switch to File.DirInternal = XUI.DefaultFolder.

If you really need the sd card:
1. Set targetSdkVersion = 29 (if not Google Play app).
2. Or use ExternalStorage.
 
Upvote 0

Skipsy19

New Member
Thks Erel,
I have removed "SetApplicationAttribute(android:requestLegacyExternalStorage, "true")" from the Manifest.

I have also installed your "ExternalStorage.b4xlib". By the way, when installing the Exemple, I get a message like :
"This app has been developped for an older version of Android bla bla bla".
Do you think there is any way to avoid this message ? An old SDK ?
Thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Do you think there is any way to avoid this message ?
No you can´t avoid it.

Android defines which SDK should be set.
If using an lower one you get this message.
 
Upvote 0
Top