admin管理员组文章数量:1533096
2024年5月20日发(作者:)
Android 基于libaums实现读写U盘文件
准备工作
在文件中引用libaums:
compile ‘:libaums:+’
在中添加权限:
L_STORAGE” /> AL_STORAGE” /> android:name=”” android:required=”false”/> android:name=”” android:required=”true” /> 代码 USBBroadCastReceiver USBBroadCastReceiver用于监听U盘的插拔,代码如下: 1. /** 2. * Author : BlackHao 3. * Time : 2018/5/10 10:07 4. * Description : USB 广播 5. * Logs : 6. */ 7. 8. public class USBBroadCastReceiver extends BroadcastReceiver { 9. 10. private UsbListener usbListener; 11. 12. public static final String ACTION_USB_PERMISSION = " _PERMISSION"; 13. 14. @Override 15. public void onReceive(Context context, Intent intent) { 16. String action = ion(); 17. switch (action) { 18. case ACTION_USB_PERMISSION: 19. // 接受到自定义广播 20. UsbDevice usbDevice = celableExtra(UsbManage _DEVICE); 21. if (leanExtra(_PERMISSION_GR ANTED, false)) { 22. // 允许权限申请 23. if (usbDevice != null) { 24. // 回调 25. if (usbListener != null) { 26. dUsbPermission(usbDevice); 27. } 28. } 29. } else { 30. if (usbListener != null) { 31. ReadUsb(usbDevice); 32. } 33. } 34. break; 35. case _USB_DEVICE_ATTACHED:// 接收到存储设备插 入广播 36. UsbDevice device_add = celableExtra(UsbManag _DEVICE); 37. if (device_add != null) { 38. if (usbListener != null) { 39. Usb(device_add); 40. } 41. } 42. break; 43. case _USB_DEVICE_DETACHED: 44. // 接收到存储设备拔出广播 45. UsbDevice device_remove = celableExtra(UsbMa _DEVICE); 46. if (device_remove != null) { 47. if (usbListener != null) {
版权声明:本文标题:Android基于libaums实现读写U盘文件 内容由热心网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:https://m.elefans.com/dianzi/1716195698a491104.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论