energypf Member Licensed User Longtime User Oct 1, 2022 #1 I am testing my App on a device with Android 4.2.2 - SDK 17, but unfortunately when I run this code it goes into error. With this code I get the error B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then kvs.Initialize(rp.GetSafeDirDefaultExternal(""),"userconfig") End If End Sub With this code it works correctly B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then kvs.Initialize(File.DirInternal,"userconfig") End If End Sub B4X: rp.GetSafeDirDefaultExternal("") return: "/storage/emulated/0/Android/data/<packname>/files" B4X: File.DirInternal return: "/data/user/0/<packname>/files" Error occurred on line: 12 (KeyValueStore) android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:341) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:238) at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:515) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:207) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:875) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:843) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671) at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44) at refertionline.rbsoft.com.keyvaluestore._initialize(keyvaluestore.java:59) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) 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.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at refertionline.rbsoft.com.main.afterFirstLayout(main.java:105) at refertionline.rbsoft.com.main.access$000(main.java:17) at refertionline.rbsoft.com.main$WaitForLayout.run(main.java:83) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5365) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Click to expand... What can I do to manage this on some older devices?
I am testing my App on a device with Android 4.2.2 - SDK 17, but unfortunately when I run this code it goes into error. With this code I get the error B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then kvs.Initialize(rp.GetSafeDirDefaultExternal(""),"userconfig") End If End Sub With this code it works correctly B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then kvs.Initialize(File.DirInternal,"userconfig") End If End Sub B4X: rp.GetSafeDirDefaultExternal("") return: "/storage/emulated/0/Android/data/<packname>/files" B4X: File.DirInternal return: "/data/user/0/<packname>/files" Error occurred on line: 12 (KeyValueStore) android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:341) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:238) at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:515) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:207) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:875) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:843) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671) at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44) at refertionline.rbsoft.com.keyvaluestore._initialize(keyvaluestore.java:59) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) 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.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at refertionline.rbsoft.com.main.afterFirstLayout(main.java:105) at refertionline.rbsoft.com.main.access$000(main.java:17) at refertionline.rbsoft.com.main$WaitForLayout.run(main.java:83) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5365) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Click to expand... What can I do to manage this on some older devices?
agraham Expert Licensed User Longtime User Oct 1, 2022 #2 I think your thread title is misleading. The file paths look OK to me, the problem appears to be with KVS. Check if you can read and write a test file to those paths using normal File operations. Upvote 0
I think your thread title is misleading. The file paths look OK to me, the problem appears to be with KVS. Check if you can read and write a test file to those paths using normal File operations.
M Mahares Expert Licensed User Longtime User Oct 1, 2022 #3 energypf said: What can I do to manage this on some older devices? Click to expand... what does your manifest code show? Upvote 0
energypf said: What can I do to manage this on some older devices? Click to expand... what does your manifest code show?
energypf Member Licensed User Longtime User Oct 1, 2022 #4 agraham said: I think your thread title is misleading. The file paths look OK to me, the problem appears to be with KVS. Check if you can read and write a test file to those paths using normal File operations. Click to expand... You're right, I corrected the title. However it fails to write to the path that GetSafeDirDefaultExternal returns. What is advisable to do in these cases? That is, should you do a writing test on the GetSafeDirDefaultExternal folder and if it fails to use the File.DirInternal? Of course it is a bit embarrassing that GetSafeDirDefaultExternal (which should return a path that allows you to write without permissions) instead returns an inaccessible path. Upvote 0
agraham said: I think your thread title is misleading. The file paths look OK to me, the problem appears to be with KVS. Check if you can read and write a test file to those paths using normal File operations. Click to expand... You're right, I corrected the title. However it fails to write to the path that GetSafeDirDefaultExternal returns. What is advisable to do in these cases? That is, should you do a writing test on the GetSafeDirDefaultExternal folder and if it fails to use the File.DirInternal? Of course it is a bit embarrassing that GetSafeDirDefaultExternal (which should return a path that allows you to write without permissions) instead returns an inaccessible path.
agraham Expert Licensed User Longtime User Oct 1, 2022 #5 Have you tried File.DirDefaultExternal? It should be the same path as GetSafeDirDefaultExternal("") but who knows! Also have you tried writing a test file using File operations as I suggested? Upvote 0
Have you tried File.DirDefaultExternal? It should be the same path as GetSafeDirDefaultExternal("") but who knows! Also have you tried writing a test file using File operations as I suggested?
energypf Member Licensed User Longtime User Oct 1, 2022 #6 File.DirDefaultExternal and GetSafeDirDefaultExternal ("") return the same path. I noticed one thing, however, that invoking File.DirDefaultExternal before using kvs.Initialize(File.DirInternal,"userconfig") not generate an error when writing the value. B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then Log(File.DirDefaultExternal) kvs.Initialize(File.DirInternal,"userconfig") End If End Sub The problem is that using File.DirDefaultExternal activates the "android.permission.WRITE_EXTERNAL_STORAGE *" permissions list which could cause Google to reject it. Upvote 0
File.DirDefaultExternal and GetSafeDirDefaultExternal ("") return the same path. I noticed one thing, however, that invoking File.DirDefaultExternal before using kvs.Initialize(File.DirInternal,"userconfig") not generate an error when writing the value. B4X: Sub Process_Globals Public kvs As KeyValueStore End Sub Sub Activity_Create(FirstTime As Boolean) If FirstTime Then Log(File.DirDefaultExternal) kvs.Initialize(File.DirInternal,"userconfig") End If End Sub The problem is that using File.DirDefaultExternal activates the "android.permission.WRITE_EXTERNAL_STORAGE *" permissions list which could cause Google to reject it.
energypf Member Licensed User Longtime User Oct 1, 2022 #7 This is the error that occurs when trying to write a simple file. B4X: Dim raf As RandomAccessFile raf.Initialize(rp.GetSafeDirDefaultExternal(""), "userconfig", False) raf.WriteInt ( 1 , raf.CurrentPosition) raf.Close Error occurred on line: 64 (Main) java.io.FileNotFoundException: /storage/emulated/0/Android/data/<packagename>/files/userconfig: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:416) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.Initialize2(RandomAccessFile.java:103) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.Initialize(RandomAccessFile.java:96) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at refertionline.rbsoft.com.main.afterFirstLayout(main.java:105) at refertionline.rbsoft.com.main.access$000(main.java:17) at refertionline.rbsoft.com.main$WaitForLayout.run(main.java:83) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5365) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) at libcore.io.IoBridge.open(IoBridge.java:400) ... 23 more Click to expand... Upvote 0
This is the error that occurs when trying to write a simple file. B4X: Dim raf As RandomAccessFile raf.Initialize(rp.GetSafeDirDefaultExternal(""), "userconfig", False) raf.WriteInt ( 1 , raf.CurrentPosition) raf.Close Error occurred on line: 64 (Main) java.io.FileNotFoundException: /storage/emulated/0/Android/data/<packagename>/files/userconfig: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:416) at java.io.RandomAccessFile.<init>(RandomAccessFile.java:118) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.Initialize2(RandomAccessFile.java:103) at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.Initialize(RandomAccessFile.java:96) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146) at refertionline.rbsoft.com.main.afterFirstLayout(main.java:105) at refertionline.rbsoft.com.main.access$000(main.java:17) at refertionline.rbsoft.com.main$WaitForLayout.run(main.java:83) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5365) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) at dalvik.system.NativeStart.main(Native Method) Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) at libcore.io.IoBridge.open(IoBridge.java:400) ... 23 more Click to expand...
agraham Expert Licensed User Longtime User Oct 1, 2022 #8 I assume that you got KVS to work on File.DirInternal? If so then it looks to me like that particular device is denying access to File.DirDefaultExternal when it shouldn't.. Both paths should be readable/writeable. I'm out of ideas I'm afraid except to say that Android 4 is so ancient can't you just ignore it? Upvote 0
I assume that you got KVS to work on File.DirInternal? If so then it looks to me like that particular device is denying access to File.DirDefaultExternal when it shouldn't.. Both paths should be readable/writeable. I'm out of ideas I'm afraid except to say that Android 4 is so ancient can't you just ignore it?
energypf Member Licensed User Longtime User Oct 1, 2022 #9 agraham said: I assume that you got KVS to work on File.DirInternal? If so then it looks to me like that particular device is denying access to File.DirDefaultExternal when it shouldn't.. Both paths should be readable/writeable. I'm out of ideas I'm afraid except to say that Android 4 is so ancient can't you just ignore it? Click to expand... Actually I could also ignore the error on this device and go without getting any other problems. I tried rightly in the forum to ask to see if for these versions of android it was recommended to use another method. Users will buy more modern devices. Upvote 0
agraham said: I assume that you got KVS to work on File.DirInternal? If so then it looks to me like that particular device is denying access to File.DirDefaultExternal when it shouldn't.. Both paths should be readable/writeable. I'm out of ideas I'm afraid except to say that Android 4 is so ancient can't you just ignore it? Click to expand... Actually I could also ignore the error on this device and go without getting any other problems. I tried rightly in the forum to ask to see if for these versions of android it was recommended to use another method. Users will buy more modern devices.
M Mahares Expert Licensed User Longtime User Oct 1, 2022 #10 energypf said: I could also ignore the error on this device and go without getting any other problems Click to expand... Now that you exhausted your options, your best bet is to export a small project that reproduces the errors you encountered. I I surely hope that many of the remaining 106000 members have a device with 4.2.2 that can test it and report back. You should never give up in this forum. Upvote 0
energypf said: I could also ignore the error on this device and go without getting any other problems Click to expand... Now that you exhausted your options, your best bet is to export a small project that reproduces the errors you encountered. I I surely hope that many of the remaining 106000 members have a device with 4.2.2 that can test it and report back. You should never give up in this forum.