Android Question hi how i copy the usbdisk's file to DirDefaultExternal 请问如何复制U盘文件到内部储存

byz

Member
Licensed User
i'm chinese ,my english just so so. 😅
its a big screen player, i want to like this:
when the USBdisk insert,auto cpoy some files to DirDefaultExternal/prog. i found in bbs and the USB lib document,but none way,i just get the usbdevice'name(test in my phone). i saw the post https://www.b4x.com/android/forum/threads/externalstorage-access-sd-cards-and-usb-sticks.90238/ but must be selected once before. can auto get the USBdisk‘spath?

一个大屏APP,我想达到如下效果:
当U盘插入的时候,自动复制一些文件到DirDefaultExternal/prog目录。
我找了论坛帖子和说明文档,没有看到合适的解决方案。https://www.b4x.com/android/forum/threads/externalstorage-access-sd-cards-and-usb-sticks.90238/ 必须先手动选择一次U盘,能不能直接获取U盘路径呢?

i think Theoretically feasible,but i don't how do it .
please help me ,thanks!
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
This question gets asked a lot on the forum - almost every week.

Android no longer allows files to be written outside of the app internal storage without getting for the User's permission first. If you are not going to put your app in the Playstore then you can compile for a lower Android version (29) or use the work-around given here .

There are some apps in the Playstore that can access external storage directly, but their developers have negotiated with Google to obtain that permission. Only full-function file utility applications are likely to succeed.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
can auto get the USBdisk‘spath?
No. The user have to select the correct path (select the correct device and select the root of this device). You can not overcome this.
This is how the SAF (Storage Access Framework) is designed.
 
Upvote 0

byz

Member
Licensed User
No. The user have to select the correct path (select the correct device and select the root of this device). You can not overcome this.
This is how the SAF (Storage Access Framework) is designed.
thanks,its different with Windows. USBmanager lib can get some info of USBdivices.but i dont kown how to copy file.(may be my wrong)
 
Upvote 0

byz

Member
Licensed User
This question gets asked a lot on the forum - almost every week.

Android no longer allows files to be written outside of the app internal storage without getting for the User's permission first. If you are not going to put your app in the Playstore then you can compile for a lower Android version (29) or use the work-around given here .

There are some apps in the Playstore that can access external storage directly, but their developers have negotiated with Google to obtain that permission. Only full-function file utility applications are likely to succeed.
ok,thanks. my app none-google(in fact china 99.99% dont use google play store),and the android divice can easy get root(because they are open the root) ,i will try,thanks again.
 
Upvote 0

byz

Member
Licensed User
my test code
B4X:
Private Sub Button3_Click 'USB测试  usbdisk test
    ToastMessageShow( rp.GetSafeDirDefaultExternal(""),False) 'i try it,but just get the inside card,not USBdisk even run the demo of ManageExternalStorage1.0.zip
    Dim str As String
    str=fs.GetExtSd
    'Msgbox(str,"SD卡路径")
    'MsgboxAsync( fs.GetDiskstats(str),"")
    ToastMessageShow(File.DirRootExternal,False)
    ToastMessageShow( fs.IsReadable(fs)    ,False )

    Dim d() As UsbDevice
    Dim um As UsbManager
    Dim ui As UsbInterface
    um.Initialize
    d=um.GetDevices
    Try

        If d.Length<>0 Then
        
            MsgboxAsync(d(0).DeviceName,"U盘名称 USBdisk Name")  'i test that can get the USBdisk
            
            If um.HasPermission(d(0))=False Then
                um.RequestPermission(d(0))
            End If
            ui=d(0).GetInterface(d(0).InterfaceCount)
            um.OpenDevice(d(0),ui,True).StartListening("UC") 'maybe wrong
        Else
            ToastMessageShow("未检测到U盘,no USBdisk",False)
        End If
    Catch
        MsgboxAsync( LastException.Message,"错误反馈")
    End Try
    
End Sub
 
Upvote 0
Top