使用Xamarin.Android中的OTG电缆从笔式驱动器复制文件,无法获取Path

时间:2017-11-29 14:07:16

标签: android xamarin.android usb-mass-storage

我已尝试过所有东西,但我无法获得pendrive的路径。

这是我的代码:

var deviceList = mUsbManager.DeviceList;
IEnumerator<UsbDevice> deviceIterator = deviceList.Values.GetEnumerator();

while (deviceIterator.MoveNext())
{
    UsbDevice device = deviceIterator.Current;

    var mPermissionIntent = PendingIntent.GetBroadcast(this.ApplicationContext, 0, new Intent(ACTION_USB_PERMISSION), 0);

    UsbManager mUsbManager = (UsbManager)this.GetSystemService(Context.UsbService);
    mUsbManager.RequestPermission(device, mPermissionIntent);

    bool perm = mUsbManager.HasPermission(device);
    if (perm)
    {
        Java.Lang.Process process = Runtime.GetRuntime().Exec("ls /storage/7EFA-0EB6");
        BufferedReader buffer = new BufferedReader(new InputStreamReader(process.InputStream));

        string listOfFiles = "";
        string line;

        while ((line = buffer.ReadLine()) != null)
        {
            listOfFiles += line + "\n";
        }

        txt.Text += listOfFiles;

        var alrt = Toast.MakeText(this as Context, "\n" + process + "\n"+listOfFiles + "this Path ", ToastLength.Long);
        alrt.SetGravity(Android.Views.GravityFlags.Center, 0, 0);
        alrt.Show();
    }
}

此外,我无法使用制造商定义的挂载点。喜欢:

/storage/UsbDriveA  
/storage/USBstorage1
/storage/usbdisk    
/storage/usbotg     
/storage/UDiskA     
/storage/usb-storage
/storage/usbcard    
/storage/usb  

正如你在这里看到的那样,我写的是硬编码的。

我被困在这2个星期。

我只需要从笔式驱动器复制一些图像文件并将其存储在应用程序数据中。

0 个答案:

没有答案