Android Question How to acess to .db file stored in a pendrive

Diego Marcelo Croatto

Member
Licensed User
Longtime User
Hello everyone... I trying to acces to a database file (.db) from an external source like a pendrive.
I try to use the the "ExternalStorage - Access SD cards and USB sticks" but i cant resolve it....

I need simply use this scheme but with external file (SQLdemo.db) stored in a pendrive.

If File.Exists (File.DirRootExternal, "SQLdemo.db") Then
SQL1.Initialize(File.DirRootExternal, "SQLdemo.db", True)
Else
File.Copy(File.DirAssets, "sqldemo.db",File.DirRootExternal, "SQLdemo.db")
SQL1.Initialize(File.DirRootExternal, "SQLdemo.db", True)
End If

Anyone can take a hand?.... Thank's a lot ;)

 

DonManfred

Expert
Licensed User
Longtime User
It only works WITH the external storage class. Asuming the Storage is successfully recognized by your device.
Use the external storage class tutorial. Let the user select the root of the pendrive.
And work with the ExternalFile from the class.

You can not use the normal File methods to work with files from a external storage.
 
Upvote 0

Diego Marcelo Croatto

Member
Licensed User
Longtime User
I try it but don't understand .... I use the example to load the device... path... etc... I need only access to file.

Dim Value As Object
Dim f As ExternalFile = Value
f = Storage.FindFile(GetCurrentFolder, "sqldemo.db")

'Msgbox(File.ReadString(File.DirInternal, "temp"), "") '<--- to here without errors!!!!

SQL1.Initialize(File.DirInternal, "temp", True) 'from here errors!

Dim Cursor1 As Cursor

Cursor1 = SQL1.ExecQuery("SELECT name FROM table1")

For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
ListViewSQL.AddTwoLines(Cursor1.GetString("name"),"item " & (i + 1))
Next


I cant resolve it! :oops:
 
Upvote 0

Diego Marcelo Croatto

Member
Licensed User
Longtime User
Don ... I'm studying the example "external storage" and this misleads me:

B4X:
  Dim in As InputStream = Storage.OpenInputStream(f)
            'We can open the image directly with Bitmap.Initialize2 however it will not allow us to use LoadBitmapResize
            'so instead we copy it to a temporary file.
            Dim out As OutputStream = File.OpenOutput(File.DirInternal, "temp", False)
            File.Copy2(in, out)
            out.Close
            ImageView1.SetBackgroundImage(LoadBitmapResize(File.DirInternal, "temp", ImageView1.Width, ImageView1.Height, True))

in this sentence

B4X:
SQL1.Initialize(File.DirInternal, "SQLdemo.db", True)

I trying with:

B4X:
SQL1.Initialize(File.DirRootExternal, "SQLdemo.db", True)

and nothing.

what is the replacement of "File.DirRootExternal" on the previous line? in the example "external file" is named "UpItem"
 
Upvote 0
Top