i try to say image on File.DirRootExternal but face erro

erfan

Member
Licensed User
Longtime User
which is better to save files: File.DirRootExternal or File.DirDefaultExtern or ...

i want to save my image which is taken by camex and this is my code:

B4X:
Dim filename,path As String
path = File.DirRootExternal 
filename="TEST.JPG"
Dim out As OutputStream
out = File.OpenOutput(path, filename, False)
out.WriteBytes(Data, 0, Data.Length)
out.Close

it works on most of phones but some phones like xperia ion and android 4 has the following error:

B4X:
An error has occurred in 
sub: preview_activity_resume (java line:272)
java.io.FileNotFoundException:/mnt/sdcard/DCIM/Camera/
TEST.JPG: open failed: ENOENT (NO such file or directory)
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Looking at my xperia right now, and I don't see a Camera folder under DCIM. I see an 'Andro100' whatever that means.
Yet, in your code I see storing at dirRootExternal. This has nothing to do with the error you're describing (at least so I suppose), since dirRootExternal is not the mnt/sdcard/dcim/camera.
 
Upvote 0

erfan

Member
Licensed User
Longtime User
thanks for your reply
this error was reported by one of the users of my program.
by the way, is saving on File.DirRootExternal the best one? even with phones without SD card?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I tend to use dirDefaultExternal, but I am not the one who can call it the 'best' way. Also, you can use the externalWritable flag, in order to check if you can write to sd. If not, you can use dirInternal.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
I'm no expert, but I remember a post by margeret that said that different devices treat external as different paths. You have /mnt/sdcard/ which probably need to be File.DirRootExternal. That is why some users report OK and other don't. or then again someone will correct me.

/mnt/sdcard/DCIM/Camera/

File.DirRootExternal & "/DCIM/Camera/"
 
Upvote 0

erfan

Member
Licensed User
Longtime User
sorry to mention it but can you write a complete code for saving which has no error on all phones. i just need to save my files in a folder. there is no difference where to save....
 
Upvote 0

erfan

Member
Licensed User
Longtime User
i tried to save my pics on File.DirInternal everything is ok but my files are pics and i want to show them in gallery. as you said here other applications dont have access to dirinternal
so what do you suggest? a place for saving which gallery can access it on all phones. even those without SD card

how is File.DirDefaultExternal ??? is it usable on all kind of phones?
 
Last edited:
Upvote 0

erfan

Member
Licensed User
Longtime User
can i trust File.DirRootExternal on all phones? with SD and without SD? ICS and gingerbread?
sorry if i ask alot
----------
i used DirDefaultExternal and faced an error on gingerbread!
 
Last edited:
Upvote 0

erfan

Member
Licensed User
Longtime User
finally i used this code in a code module(as dear Erel advised me):

B4X:
Dim pathn As String

If File.ExternalWritable= True Then
pathn = File.DirRootExternal  
Else
(......)
End If


i use Code.pathn in all of the project to save my pics and open them in gallery. so far I had no problem in ICS or gingerbread. but didnt test it on phones with no SDcard.

plz let me know if you have any idea for (.........)
i dont know what happens in phones with no SD card such as xperia u and wich code should i use.
 
Last edited:
Upvote 0

erfan

Member
Licensed User
Longtime User
Thanks Erel

i used File.DirRootExternal and it worked well even on Xperia U which has no External memory Card
 
Last edited:
Upvote 0
Top