Write to /mnt/extsd

sconlon

Active Member
Licensed User
Longtime User
My Android tablet has a microSD slot which appears in Astro file manager as /mnt/extsd. I have inserted a 16gb card into this and am able to see any files on it again is Atsro. In my app I want to backup a database to this device so I have used:

File.Copy(File.DirRootExternal,"test.db","/mnt/extsd/","test_backup.db")

But I get a error "libcore.io.ErrnoException: open failed: EACCES (Permission denied)"

Earlier in the app I have used DirRootExternal so I believe that should add the necessary permission WRITE_EXTERNAL_STORAGE to the manifest file.

Any suggestions?

Ta.
 

sconlon

Active Member
Licensed User
Longtime User
Yes, I can read a file from it ok. So how can I change or set write permission on this device. Can it be done within the app or maybe set permanently by some other means? I can write to it on my PC ok so it is not the card itself!
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
I'm using a Chinese tablet CCP P735 which is ok but has some peculiarities and this could be one of them. However, I looked at the link you gave me and noted the suggestion to 'Add an additional group definition for this permission...<group gid="media_rw" />' I'm not sure how exactly to do this with the Manifest editor - I'm not very familiar with the format of the Manifest file. Can you help?

Ta
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
Ok. haven't rooted an Android device before but from reading stuff on various forums it seems the process could be different for each tablet and I need to consult with the manufacturer - some hope with that!
 
Upvote 0

RJB

Active Member
Licensed User
Longtime User
In a similar vein:

if I try this code in debug mode it works:
/code
File.MakeDir("/mnt/sdcard" , "TestFiles")
Dim TW As TextWriter
TW.Initialize(File.OpenOutput("/mnt/sdcard/TestFiles", "Test.txt", False))
TW.Write(teststring)
TW.Close
/code

The directory is made and the file is written

If I try it in release mode it fails to create the directory and gives the error:
java.io.FileNotFoundException: /mnt/sdcard/TestFiles/Test.txt: open failed: ENOENT (No such file or directory)

or if the directory is there the file write fails.

Any suggestions?
Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use File.DirRootExternal instead of hardcoding the path. Your current code will not work on all devices.

When the compiler sees a call to File.DirRootExternal (or DirDefaultExternal) it adds the "write storage" permission. This permission is added automatically in debug mode. This is why it fails in release mode.
 
Upvote 0
Top