Android Question Detect and use SD Card

nibbo

Active Member
Licensed User
Longtime User
I have read on other threads that you can use File.ExternalWritable to detect an SD card.
When I try this however it returns true! There is definitely no SD card in the slot!
B4X:
'    check for an sd card
If Not(File.ExternalWritable) Then
    Msgbox("This application requires an SD card to hold the data and images","Error")
    Activity.Finish
End If

As this test failed my app went on to try to create the directories which also worked.
They have been created on the internal storage under /storage/emulated/0/...
Samsung Galaxy Tab 3 Android version 4.2.2.

Any ideas anyone?

Thanks
 

nibbo

Active Member
Licensed User
Longtime User
Just tried it on an older Motorola using 4.0.4 and that does even worse...
It does not detect the missing SD card so again it carries on tio try to create the directories which does not fail nor
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you could use a TRY/CATCH on a filewrite to File.DirDefaultExternal.

I wrote some code last week that downloaded data to that location when I tried it on an out of use phone I got an error and it appeared that there was no SD inthere. So the error catch should give you the notification that there isn't an SD card inserted.
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User

Thanks Sorex, I tried your suggestion and no errors were trapped.
So... I had a search around and the file was created in the android/data/<my_app_nams>/files

I added a couple of msgbox's and they actually show that File.DirDefaultExternal does indeed point to /storage/emulated/0/android/data/<my_app_name>/files

Is this a config setting or something?

Thanks again
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
strange. Where does it install when you insert the SD?

should be something like SD:\Android\Date\appname I believe
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Furthermore... I ran the same tests on the Motorola.
This time Files.DirDefauleExternal does point to the sdcard.
However, creating and writing a file to the SD card neither works or reports an error!
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
strange. Where does it install when you insert the SD?

should be something like SD:\Android\Date\appname I believe

Sorry Sorex, I am not sure I understand what you are asking me here.
If you mean when I install the app, they always go under this /storage/emulated/0/android/data/...
It looks like my tablet thinks this is the external storage.
I will have a good google and see exactly what this storage/emulated bit means.
Thanks again for your time.
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
OK, I am no further forward with a 'fix'.
I can continue developing/testing if I replace File.DirDefaultExternal with '/storage/extSdCard/testdir...'
This means my app is not very portable so I would love to know why DirDefaultExternal is not referencing the correct directory.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
Why would Google discourage the use of SD cards?
It would be like Microsoft not supporting external drives!
Most devices only have 16GB internal store so surely it makes no sense to restrict the entire devices capabilities to that alone?
Not questioning your expertise just can't imagine why they would do this!
My app will need to access a few thousand images which I was hoping to pre-load on a Micro SD to save users from having to download them from a remote.
Now all my users will need to leave a download process running for up-to 45 hours, using their data allowances, when they could just pop an SD card in and have instant access to the images.
Sometimes I do wonder what these people are thinking.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just wondering... what kind of app is that that it needs gigs of images?
 
Upvote 0

nibbo

Active Member
Licensed User
Longtime User
just wondering... what kind of app is that that it needs gigs of images?

Sales presenters.
We have over 6000 stock lines (growing all the time) and want to be able to show the images at trade shows etc...
Our products can be quite intricate so we do need fairly good resolutions also.
We will also want to show them at customer sites where Wi-Fi & 3g are not available, hence the need to store them locally.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…