Android Question Place sqLite DB on external storage (SD Card)

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I wish to use an sqlite db on a tablet's external sd card.

The tablet is running Android Build version 6 with API Level (19 KiKat).

I tried ExternalStorage.zip. I had to edit the manifest to a minimum of 19 to get it to install.

It now installs and runs, but when I push the Pick Folder button it doesn't do anything. I get no errors.

I also tried Erels's test code:
B4X:
Dim extFolder As ExternalFile = Storage.FindFile(Storage.Root, folder)
Log("Folder found: " & extFolder.IsInitialized)
If extFolder.IsInitialized Then
   Dim extFile As ExternalFile = Storage.FindFile(extFolder, filename)
   Log("File found: " & extFile.IsInitialized)
   If extFile.IsInitialized Then
       Dim rp As RuntimePermissions
       Dim out As OutputStream = File.OpenOutput(rp.GetSafeDirDefaultExternal(""), filename, False)
       File.Copy2(Storage.OpenInputStream(extFile), out)
       out.Close
   End If
End If

However this wouldn't compile as it seems to need a library. I don't understand how to use it. I have looked at the tutorials on permissions, but that didn't help.

Thanks in advance for any help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The tablet is running Android Build version 6 with API Level (19 KiKat).
There is no such version. Your device is running Android 4.4.

Accessing sd cards is problematic on Android 4.4 as the OS doesn't allow you to access it directly and the underlying external storage framework is not fully supported.
Your best option is to use a newer version of Android.

Copying parts of the code will not help. You need to run the example and see whether it works on your Android 4.4 device, after you change the minSdkVersion.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
There is no such version. Your device is running Android 4.4.

Accessing sd cards is problematic on Android 4.4 as the OS doesn't allow you to access it directly and the underlying external storage framework is not fully supported.
Your best option is to use a newer version of Android.

Copying parts of the code will not help. You need to run the example and see whether it works on your Android 4.4 device, after you change the minSdkVersion.

Thanks Erel,

No the example doesn't work.

I assume that when you suggest I use a newer Android version you are referring to replacing the operating system that is installed on the tablet.

Is my assumption correct?

If I need to upgrade the operating system can you point me to some web info on how I would do this. The tablet I have doesn't seem to have an upgrade/update feature as its a cheap Chinese generic that I am using as a display and logging device..

Sadly I am an only embedded C and Matlab programmer and only have a very basic knowledge of Android.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
What do you see? Is there any error message?

Hi Erel,

No error message at all. The app keeps running. You can check and uncheck the checkbox which suggests the app hasn't stalled, but no list appears. I have tried it on my Android Phone which is API level 23 Build Version 6.0.1 according to the ResCheck app I use to find the screen res etc. It works fine on my phone.

I traced the program through with the debugger with a brekpoint on the Pick Folder Button click. It gets to Line 41 (Wait For Storage_ExternalFolderAvailable, but never gets any further than this. It is obviously waiting for the Storage_ExternalFolderAvailable to complete.

I can see the SD Card in the file manager and can copy data to it.

On the tablet when it does the ion_event sub it jumps straight to the Return Null statement at line 126. When it enters this sub Args(0) = 0x0 and Arg(1) = null.

On my phone it never gets to the ion_event at all as far as I can work out.

Best regards

Rob
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Hi Rob,


I did a lot of testings and reading about accessing the SD card. To make a long story short, you have two options:

  • The first and simplest is to install your program first and then move it to the SDcard while use the program area also for storage of a database. Pro its simple, cons other programs don have access to it.
  • The second option is access to a SDcard via the Storage Frame work to create, and select a directory on the SDcard. Pro other programs can access and sharing the same database. Cons the Storage Frame work interface can be a little intimidate the non-technical user. However normally the user has only one time define the location of the database location on the SDcard.

Be also aware the current security is more restricted then in the past so you can’t get anymore the old examples working today. And Android security is moving to implement more restricted access to SDcard in the future.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks for that.

I have upgraded the tablet I am using to a Lenovo M10 running API 28. I gave up on the Chinese Generics (Mediatek) as the power management system is very flaky. It's a pity because they are OK as long as you don't try and run them continuously which I must do for my application. So far the Lenovo seems a nice machine.

I will have a look at the options you have suggested.

I have my app working nicely now, but I do have another question which I will put in a new post.

Best regards

Rob
 
Upvote 0
Top