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

Discussion in 'Android Questions' started by Daniel44, Aug 10, 2019.

  1. Daniel44

    Daniel44 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:)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    1. Please post the error message.

    2. Do you really want to copy the file to an external sd card (not File.DirRootExternal)?
     
  3. Daniel44

    Daniel44 Member Licensed User

    Thanks for answer my question Erel. I could fix it with this:

    Code:
    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:

    Code:
    '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: Aug 11, 2019
  4. Erel

    Erel Administrator Staff Member Licensed User

    No permission is needed when you copy to FileDirInternal.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice