我已尝试过所有东西,但我无法获得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个星期。
我只需要从笔式驱动器复制一些图像文件并将其存储在应用程序数据中。