弹出USB大容量存储设备时出问题 的解决方法

原因:

有程序正在占用着U盘活移动硬盘。

解决方法:

找到事件查看器,打开

点击 管理事件,警告,在 常规 中看到 进程的ID,从任务管理器中,找到PID为此的进程结束掉即可。

再次弹出设备即可成功。

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
要在Android应用程序中访问USB设备,您需要执行以下步骤: 1. 在AndroidManifest.xml文件中添加以下权限: ``` <uses-feature android:name="android.hardware.usb.host" /> <uses-permission android:name="android.permission.USB_PERMISSION" /> ``` 2. 检测连接的USB设备: ``` UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList(); if (!usbDevices.isEmpty()) { // USB设备已连接 UsbDevice device = usbDevices.get(deviceName); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); usbManager.requestPermission(device, pendingIntent); } else { // 没有连接的USB设备 } ``` 3. 处理用户授权: ``` private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; BroadcastReceiver usbReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (ACTION_USB_PERMISSION.equals(action)) { synchronized (this) { UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if (device != null) { // 授权成功,可以开始访问USB设备 } } else { // 用户拒绝了授权请求 } } } } }; registerReceiver(usbReceiver, new IntentFilter(ACTION_USB_PERMISSION)); ``` 4. 访问USB设备: ``` UsbDeviceConnection connection = usbManager.openDevice(device); UsbInterface usbInterface = device.getInterface(0); UsbEndpoint endpoint = usbInterface.getEndpoint(0); connection.claimInterface(usbInterface, true); byte[] buffer = new byte[endpoint.getMaxPacketSize()]; int count = connection.bulkTransfer(endpoint, buffer, buffer.length, TIMEOUT); ``` 请注意,这仅是一个简单的示例,并且需要根据您的具体需求进行修改和优化。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值