External Sdcard Path

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have developed SQLite application with Data path as Phone memory (/mnt/sdcard/),but now I replaced Data path in external sdcard (/mnt/sdcard/extstorages/sdcard/).For this, my applcation not able to read external storage card Data.

My Code is given below

sql.Initialize(File.DirRootExternal & "/extstorages/sdcard/Data/" ,"Config.S3db",True).

Pls advise how to solve this problem
 

junaidahmed

Well-Known Member
Licensed User
Longtime User
Sorry,My statement is like you say,but can't able to read data from external memory card

SQL.Initialize(File.DirRootExternal, "/extstorages/sdcard/junaid/Data/Config.S3db/",True)
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Really I m facing problem,Pls help how to read data from external sdcard like

sql.Initialize(File.DirRootExternal & "/extstorages/sdcard/Data/" ,"Config.S3db",True).
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Actually my device is Samsung Galaxy Tab 7.7 with Android 3.2 Version.
I would like to read data from removable device.Pls tell me exact path of removalble device.The removable device that come under /mnt/sdcard/

Note :-
/mnt/sdcard/ ----------> Root sdcard

extstorages/sdcard/ ---------> Removable Sdcard
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
hi junaid,
you are not giving much information:
1/ what error do you get when you try parijs's solution
B4X:
SQL.Initialize(File.DirRootExternal, "/data/Config.S3db",True)

2/ what is the result of Log(File.DirRootExternal) on your device

3/ Is you solution supposed to work on all Android devices?
 
Upvote 0

latcc

Banned
Android has still not standardised the addressing of external memory locations. As I understand it there are two parts to a device's address to storage.

1. Root

2. pathname-of-card

The function 'File.DirRootExternal' uses a standard root but won't work on many tablets and phones because 'root names' are different for most tablets (as they are customised by the OEMs who design them). Tablets are more prone to using custom root naming as Android does not support all the various internal and external memory that these devices often have.

You will need to use a hard-wired pathname call rather than the standard 'File.DirRootExternal' for external memory calls. In fact, you will have to use this method to address many SD-CARD memory locations too. It is, in fact, the only way to address non-standard root memory in tablets and some phones.

The subroutine below should be called and it will test various known non-standard root/pathnames for devices, and return the rootpath to you for hardwiring in a call to the external card.


Sub GetSDCardFolder() As String
'*************************************************************
'Try to find the location of removable external sdcard memory,
'*************************************************************
Dim root As String
Dim folder As String
Dim sdf As String

'------------------------------------
'DEFAULT
'-------------------------------------
root = File.DirRootExternal
folder = ""
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
'HTC Desire
'-------------------------------------
root = "/mnt"
folder = "sdcard"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
' Acer A500 Tablet
'------------------------------------
root = "/mnt"
folder = "external_sd"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
'Samsung Galaxy S2
'-------------------------------------
root = File.DirRootExternal
folder = "external_sd"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'-------------------------------------
' ASUS TF 101 (Micro SD)
'-------------------------------------
root = "/mnt/sdcard/Removable"
folder = "MicroSD"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'-------------------------------------
'HTC
'-------------------------------------
root = File.DirRootExternal
folder = "sd"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'-------------------------------------
'MOTOROLA DROID 3
'-------------------------------------
root = "/mnt"
folder = "sdcard-ext"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
' Flytouch 3 Tablet
'------------------------------------
root = "/mnt"
folder = "sdcard1"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
' Flytouch 3 Tablet #2
'------------------------------------
root = "/mnt"
folder = "sdcard/sdcard1"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
'------------------------------------
' LG 3D Tablet
'------------------------------------
root = "/mnt"
folder = "sdcard/_ExternalSD"
If File.IsDirectory(root,folder) Then
sdf=root & "/" & folder
If Writetest(sdf) Then Return sdf
End If
End Sub


Sub WriteTest(dirname As String)
As BooleanDim s As String
Try
File.WriteString(dirname,"test.tmp","test")
s=File.ReadString(dirname,"test.tmp")
File.Delete(dirname,"test.tmp")
Catch
Log(LastException.Message)
Return False
End Try
If s="test" Then return true
End Sub

Call it with:

CardPath = GetSDCardFolder

where CardPath is a string variable (dim CardPath as string) (you can use any string you wish)


and you use string in 'CardPath' in place of the standard path calling function (File.DirRootExternal)...

File.OpenInput(CardPath, "myfile.txt")


Naturally you should use your own device's root/path details to this list first.

The original thread to which this code originates can be found here: http://www.b4x.com/forum/basic4andr...n-about-writing-external-storage-sd-card.html

Hope this helps.
 
Last edited:
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Once again sorry to all,Actually I would like to Display Images from External sdcard (not root sdcard) in Imageview,the Image not displaying in Imageview,it shows an error "File Not Found Exception".But its working when the image in root sdcard (/mnt/sdcard/). .Pls see the below code.

Imageview.Bitmap = LoadBitmap(File.DirRootExternal,"/Photo1.jpg") --->It's working fine for root sdcard

Imageview.Bitmap = LoadBitmap(File.DirRootExternal & /extstorages/sdcard,"/Photo1.jpg") --->It's not working for external sdcard.

Imageview.Bitmap = LoadBitmap("/mnt/sdcard/extstorages/sdcard","/Photo1.jpg") --->It's also not working for external sdcard..

My Actual External sdcard Path is /mnt/sdcard/extstorages/sdcard
.

Pls see the above three Statement and advise how to solve this issue.
 
Last edited:
Upvote 0

Dallas Williams

Member
Licensed User
Longtime User
I'm having a similar problem, I can read from the storage card but cannot write

Samsung Galaxy Tablet 7"
Android 3.2

The directory is case sensitive - I suggest you figure out if you can see the file first.

Log(File.Exists(File.DirRootExternal & "/extStorages/SdCard/", "Photo1.jpg"))
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Now it's working.Thanks for your quick reply.

I think You can write external sdcard by adding permission in AndroidManifest.xml file.see the below statement then try.

AddManifestText(
<uses-sdk android:minSdkVersion="4" />
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE>)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
I solved this problem this way:

In Sub Globals:
B4X:
Dim RightSDCard As String

In Sub Activity_Create:
B4X:
Dim sdcheck As MLfiles
If sdcheck.isDir("/mnt/sdcard2/") = True Then
RightSDCard = "/mnt/sdcard2/"
Else
RightSDCard = "/mnt/sdcard/"
End If

In my project i used it then this way:
B4X:
  File.MakeDir(RichtigerSDKartenPfad, "someDir")
 
Upvote 0
Top