Android Question SQLite db file doesn't copy in my android v6 sdcard device

Daniel44

Active Member
Licensed User
Hi Everyone!

Well.. I developed an app and I'm testing it on leapdroid 18 (android 4.4) it works fine.. but when I install it on a real device with Android 5 or 6 my app crashes. It seems the database file is not copied to the sdcard. Im using DBUtils 2.06 and my db file is copied in the file manager on my project.

Is there any function or method for android versions higher than 4.4 my app works and copy to sdcard the database file? Please if anyone knows how to do it and can share it here I would appreciate it very much. From now on and in advance thank you very much:)
 

Daniel44

Active Member
Licensed User
Thanks for answer my question Erel. I could fix it with this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
 
    If FirstTime Then
        CopyDBIfNeeded("base.db")
        Connection.mySQL.Initialize(File.DirInternal, "base.db", False)
    End If
end  sub


Sub CopyDBIfNeeded (Filename As String)
    If File.Exists(File.DirInternal, Filename) = False Then
        File.Copy(File.DirAssets, Filename, File.DirInternal, Filename)
    End If
End Sub

then into the manifest editor this:

B4X:
'End of default text.
AddManifestText(<uses-permission
android:name="Android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
and it works well although it does not copy the database to the actual device. In the Android V 4.4 emulator the above code was not required and the database file was automatically copied to the sdcard. And I know that because inside the emulator went to its sdcar and there was the database but in Android 6.01 I can not. the same works. I think it didn't work before because Android saw it as a dangerous permission. I don't know.
 
Last edited:
Upvote 0
Top