Android Question Path to read/write file on a USB memory stick

Sergio83

Member
Licensed User
Longtime User
Hi all of you,

My purpose is to capture MJPEG stream from wifi camera and read/write the stream content on a usb memory stick.

Connecting to cameras and catching theire mjpeg streams is OK, but where I bug is to find the path of the USB memory stick to record the streams.

While walking across the forum I found many pieces of code but no one gave me an answer to really fix my problem

My environment:

Android TV box
2 USB port (host)
OS version 4.4.4 (seems to be important)

Many thanks by advance to anybody able to help me!

Regards
 

Sergio83

Member
Licensed User
Longtime User
You really need help to open a commandline window on windows? HERE: http://lmgtfy.com/?q=open commandline window
Hi DonManfred,

I understand your interrogation!

I'm a beginner with B4A and I'm most familiar with Linux than with Windows but at this point surely no (I'm more than 66 years old, I'm retired and my job was IT engineer!)

I was just wondering about the formulation "<android sdk>" which is in fact the path to the SDK folder.

But surely I appreciate joking !!!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I was just wondering about the formulation "<android sdk>" which is in fact the path to the SDK folder.
yes, it is the path to your sdk installation.

Open a command window, navigate (chdrive, cd) to the sdk-dir/tools and run the command erel suggested and to know if it prints an error or not.

But surely I appreciate joking !!!
In fact i was not joking
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Hello guys (Erel, Marco, DonManfred)

I tried what Erel proposed me and I've just got a blank line as answer to the command "adb devices", may be I mistaken ?

But for the moment I don't care, because concerning the implementation of version 6.50 everything is fine which ends well, my first intent about the corruption of the SDK was the right, partly confirmed by Erel.

I reinstalled the SDK and the compilation / installation / execution are ok.

No problem with any old librairies at this moment let's see later if any appears.

Now I can tackle my original problem: to know the accessible directories on mounted usb stick or hdd, that's what I bought version 6.50 on the advice of Erel

Just for you DonManfred, do not take badly what you are going to read because I have a lot of respect for your level of expertise regarding B4A, but I assure you DonManfred joking is good for health, try, you will adopt it.

Can we consider that that thread is not closed because the originla issue is still alive from my side.

I will let you know soon the result of my testing with runtime permission

Thanks a lot for your help all of you

Regards
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Hi again guys

First result of my test.

Just to recall, my environment:

Android box with 2 USB host port
Android 4.4.4
B4A 6.50

I've a USB stick (fat32 formatted) pluged in the first usb port, it appears in settings has mounted and usb 0

The response of GetAllSafeDirsExternal ("") gave me just one entry in the receiving list which is:
B4X:
/mnt/internal_sd/Android/<package name>/files

Do I have to create some specific folder on the stick like "Android/data/<package name>/"?

I remember Erel said in one of his posts regarding this fucntion that Android 6.0 and B4A are required, infortunatly I'm running 4.4.4 as you know is that the issue?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This means that it will be more difficult. What is the output of this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim p As Phone
   Dim stdout As StringBuilder
   Dim stderr As StringBuilder
   stdout.Initialize
   stderr.Initialize
   p.Shell("mount", Null, stdout, stderr)
   Log("stdout: " & stdout)
   Log("stderr: " & stderr)
End Sub
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Erel,

I've done what you ask me, the result:

B4X:
Installing file.
GC_FOR_ALLOC freed 620K, 23% free 3233K/4184K, paused 17ms, total 17ms
GC_FOR_ALLOC freed 620K, 23% free 3233K/4184K, paused 17ms, total 17ms
GC_FOR_ALLOC freed 620K, 23% free 3233K/4184K, paused 17ms, total 17ms
GC_FOR_ALLOC freed 620K, 23% free 3233K/4184K, paused 18ms, total 18ms
PackageAdded: package:Domus.SeriSyvis
Copying updated assets files (51)
** Service (starter) Create **
2017-02-13 17:31:02.881:INFO::jetty-7.x.y-SNAPSHOT
GC_FOR_ALLOC freed 648K, 23% free 3226K/4180K, paused 19ms, total 19ms
2017-02-13 17:31:02.930:INFO::started o.e.j.s.ServletContextHandler{/,null}
2017-02-13 17:31:02.937:INFO::Started [email protected]:5555 STARTING
org.eclipse.jetty.server.Server@41cd5bd0
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
stdout: rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,seclabel,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,mode=600 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
adb /dev/usb-ffs/adb functionfs rw,relatime 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
selinuxfs /sys/fs/selinux selinuxfs rw,relatime 0 0
none /sys/fs/cgroup tmpfs rw,seclabel,relatime,mode=750,gid=1000 0 0
none /sys/fs/cgroup/memory cgroup rw,relatime,memory 0 0
/sys/kernel/debug /sys/kernel/debug debugfs rw,relatime,mode=755 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
tmpfs /mnt/secure tmpfs rw,seclabel,relatime,mode=700 0 0
tmpfs /mnt/asec tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,seclabel,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/usb_storage tmpfs rw,seclabel,relatime,mode=555,uid=1013,gid=1023 0 0
/dev/block/rknand_system /system ext4 ro,seclabel,nosuid,nodev,relatime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/rknand_cache /cache ext4 rw,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/rknand_metadata /metadata ext4 rw,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc 0 0
/dev/block/rknand_userdata /data ext4 rw,seclabel,nosuid,nodev,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/fuse /mnt/shell/emulated fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
/dev/block/vold/8:1 /mnt/usb_storage/USB_DISK0/udisk0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/31:13 /mnt/internal_sd vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
stderr:
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Is /mnt/usb_storage the correct path?
You asked me to run a "mount" command and the result is clear regarding the usb stick: it is mounted as
B4X:
/mnt/usb_storage/USB_DISK0/udisk0
I will test this path I think it should be OK, but why "GetAllSafeDirsExternal" does not take of this mount point?
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Hello Erel,

As I was expecting the whole path I stated works fine, but you must be ok with me, that is not the good way to hard-code a path spefic to a device.

So I ask my question again:

Why "GetAllSafeDirsExternal" does not take care of this mount point?

Remember you Erel I upgraded my current B4A 5.50 version to 6.50 on your advise just for that ...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why "GetAllSafeDirsExternal" does not take care of this mount point?
I was mistaken. GetAllSafeDirsExternal doesn't return the paths of USB mounted devices. There is no API in Android that returns this path.

You will need to parse it from the output of mount.

Remember you Erel I upgraded my current B4A 5.50 version to 6.50 on your advise just for that ...
If you like you can return to v5.50 and I will cancel the order.

Note that I wrote:
Try RuntimePermissions.GetAllSafeDirsExternal. It returns all known accessible paths.

I wasn't 100% that it will work.
 
Upvote 0

Sergio83

Member
Licensed User
Longtime User
Hello Erel,

I understand the situation ...

When you answered me
This means that it will be more difficult
I suspected the issue and anticipated your proposal about parsing the output of the mount command, I'm on my way to code it.

As for the reimbursement, I appreciate your offer but since all my applications and my environments have been migrated to 6.50 I propose you another deal: to get the next major release of B4A at no cost.

Is that OK for you?

Anyway, you and the guys who are at your side made and continue to make a super good job. I never thought that a day i can use a so easy and so powerfull tool to devlop Android apps.

Regarding what I said in another post about the difficulty to run a home automation server with no human intervention, I change my mind in pite of requestpermission human intervention needed for usb to serial adaptor or HID raw device. I turned it around either with esp8266 (NodeMCU ) via MQTT for serial connexion or the small TP-Link wifi router (WR703N) running OpenWRT for HID raw device.

I've almost finish porting!

Best regards
 
Upvote 0
Top