本文实例为你们分享了android经过usb读取U盘的具体代码,供你们参考,具体内容以下java
1.关联 compile ‘com.github.mjdev:libaums:+'android
2.权限设置git
3.监听u盘 插入拔出的广播github
//监听otg插入 拔出
IntentFilter usbDeviceStateFilter = new IntentFilter();
usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
mContext.registerReceiver(UDiskMountedReceiver, usbDeviceStateFilter);
//注册监听自定义广播
IntentFilter filter = new IntentFilter(Constant.ACTION_USB_PERMISSION);
mContext.registerReceiver(UDiskMountedReceiver, filter);
4.代码数组
package com.zb.usbtest;
/**
* @项目名: UsbTest
* @包名: com.zb.usbtest
* @文件名: ReadUDisk
* @建立者: 25934
* @建立时间: 2018-07-24 13:50
* @描述: TODO
*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.util.Log;
import com.github.mjdev.libaums.UsbMassStorageDevice;
import com.github.mjdev.libaums.fs.FileSystem;
import com.github.mjdev.libaums.fs.UsbFile;
import com.github.mjdev.libaums.partition.Partition;
import j