I must be missing something. I use the same code in many apps.
This code creates a directory for my app's data:
In all cases until now, I have found the desired folder being created and the file copied in it.
For some reason, on this Android 6.0 tablet (not my normal development target, I normally use an Android 5.1 phone) the AppFolder directory does not get created (even though it does find the File.ExternallWritable...
I single stepped through the code and it runs without issue including the File.MakeDir() statement until the File.Copy() call where it crashes with this error:
When I look for the AppFolder directory with a file manager after the app crashes, I do not find it.
Of course, the same code on the Android 5.1 phone works fine. Not sure if it is related to the Android version (probably not since I have many other apps that work fine on this tablet).
The app name is "TripRecorder". No space, no special characters.
The Build Configuration is: b4a.TripRecorder
The TargetSdkVersion is 26
I have set #CanInstallToExternalStorage: True
I have apps with the same code running on that tablet, so why this particular app does not work is a mystery to me.
Open to any suggestion and thanks in advance!
Edit: I made another test, trying to copy the file to the existing Download folder and that fails too. The app finds the file in the DirAssets folder, finds the Download folder exists but crashes when trying to write the file with this:
This code creates a directory for my app's data:
B4X:
If File.ExternalWritable = True Then
If File.IsDirectory( File.DirRootExternal, AppName & "/" ) = False Then
File.MakeDir( File.DirRootExternal, AppName )
End If
AppFolder = File.DirRootExternal & "/" & AppName
End If
If File.Exists( File.DirAssets,"somefile.txt" ) = True Then
File.Copy( File.DirAssets, "somefile.txt", AppFolder, "somefile.txt" )
End If
For some reason, on this Android 6.0 tablet (not my normal development target, I normally use an Android 5.1 phone) the AppFolder directory does not get created (even though it does find the File.ExternallWritable...
I single stepped through the code and it runs without issue including the File.MakeDir() statement until the File.Copy() call where it crashes with this error:
B4X:
*** Service (starter) Create ***
Error occurred on line: 163 (Starter)
java.io.FileNotFoundException: /storage/emulated/0/TripRecorder/somefile.txt: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:373)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:339)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at b4a.TripRecorder.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
at android.app.ActivityThread.access$1900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
... 20 more
When I look for the AppFolder directory with a file manager after the app crashes, I do not find it.
Of course, the same code on the Android 5.1 phone works fine. Not sure if it is related to the Android version (probably not since I have many other apps that work fine on this tablet).
The app name is "TripRecorder". No space, no special characters.
The Build Configuration is: b4a.TripRecorder
The TargetSdkVersion is 26
I have set #CanInstallToExternalStorage: True
I have apps with the same code running on that tablet, so why this particular app does not work is a mystery to me.
Open to any suggestion and thanks in advance!
Edit: I made another test, trying to copy the file to the existing Download folder and that fails too. The app finds the file in the DirAssets folder, finds the Download folder exists but crashes when trying to write the file with this:
B4X:
Copying updated assets files (8)
*** Service (starter) Create ***
Error occurred on line: 179 (Starter)
java.io.FileNotFoundException: /storage/emulated/0/Download/somefile.txt: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:373)
at anywheresoftware.b4a.objects.streams.File.Copy(File.java:339)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at b4a.TripRecorder.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
at android.app.ActivityThread.access$1900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
... 20 more
Last edited: