usbManager = new UsbManager(); usbManager.printUsbState(); // 添加一项flag usbManager.addFlag(UsbFlags.CONNECTED...); // 添加一组 flag usbManager.addFlag(EnumSet.of(UsbFlags.ACCESSORY, UsbFlags.ADB)); // 检查存在的一个flag...(EnumSet.of(UsbFlags.NCM, UsbFlags.MTP))); usbManager.printUsbState(); // 删除一个不存在的flag usbManager.removeFlag...(UsbFlags.MTP); // 删除一个存在的flag usbManager.removeFlag(UsbFlags.ACCESSORY); // 删除一组都不存在的flag usbManager.removeFlag...usbManager.removeFlag(EnumSet.of(UsbFlags.ADB, UsbFlags.ACCESSORY)); } 输出为 Current usb state is []
整个开发流程可以总结为以下几点: 1.发现设备 UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE...); Map usbList = usbManager.getDeviceList(); 通过UsbManager这个系统提供的类,我们可以枚举出当前连接的所有usb...usbManager.hasPermission(usbDevice)) { usbPermissionReceiver = new UsbPermissionReceiver();...synchronized (this) { UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE...它的获取也很简单,就一句代码: usbDeviceConnection = usbManager.openDevice(usbDevice); 到这里,理论上平板和usb外设之间的连接已经建立了,也可以首发数据了
UsbManagerService as ILocalObject).GetObjectID); end; 获取USB设备列表 function GetUsbDevices: TArray<JUsbDevice ; var UsbManager...: JUsbManager; UsbDeviceList: JHashMap; UsbDeviceListIterator: JIterator; I: Integer; begin UsbManager...:= GetUsbManager; if UsbManager < nil then begin UsbDeviceList := UsbManager.getDeviceList; SetLength...; end; 打开USB设备,返回USB连接接口 function GetUsbConnection(Device: JUsbDevice): JUsbDeviceConnection; var UsbManager...: JUsbManager; begin UsbManager := GetUsbManager; if UsbManager < nil then Result := UsbManager.openDevice
ACTION_USB_PERMISSION = "com.android.usb.USB_PERMISSION"; // 获取USB设备列表及定位到要申请权限的USB设备 // mUsbManager = (UsbManager...ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED...); filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); mContext.registerReceiver(mUsbReceiver...mContext.unregisterReceiver(mUsbReceiver); UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE...); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false) && currentDevice.equals
); usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); mContext.registerReceiver...UsbMassStorageDevice[] storageDevices; private List<UsbFile usbFiles = new ArrayList< (); private final UsbManager...); usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); mContext.registerReceiver(UDiskMountedReceiver...= null) { mOnUDiskCallBack.onPermissionCallBack(); } break; case UsbManager.ACTION_USB_DEVICE_ATTACHED...= null) { mOnUDiskCallBack.onAttachDeviceCallBack(); } break; case UsbManager.ACTION_USB_DEVICE_DETACHED
// 获取相关的 Usb 设备 UsbDevice attachUsbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE...private void permissionRequest() { // 设备管理器 UsbManager usbManager = (UsbManager) MainActivity.getContext...case ACTION_USB_PERMISSION: UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE...); if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if (usbDevice...); usbDeviceFileter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); usbDeviceFileter.addAction
接下来就得hook下了,通过frida hook,发现了出现UsbManager的调用,通过UsbManager是可以获取到当前连接的Usb设备,并且通过UsbInterface就可以知道是否是音频设备...接下来就需要知道如何被动感知到Usb 设备连接了,看到有这样的2个广播: UsbManager.ACTION_USB_DEVICE_ATTACHED UsbManager.ACTION_USB_DEVICE_DETACHED
null) return; Context appContext = context.getApplicationContext(); mUsbManager = (UsbManager...* * @param appContext * @param usbManager */ public static void loadDriver(Context...appContext, UsbManager usbManager) { driver = new CH34xUARTDriver(usbManager, appContext, ACTION_USB_PERMISSION
); usbDeviceStateFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mOtgReceiver...); //允许权限申请 if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { if (usbDevice !...://接收到U盘设备插入广播 UsbDevice device_add = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (device_add...= null) { //接收到U盘插入广播,尝试读取U盘设备数据 redUDiskDevsList(); } break; case UsbManager.ACTION_USB_DEVICE_DETACHED...usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); //获取U盘存储设备 storageDevices = UsbMassStorageDevice.getMassStorageDevices
import android.content.Context; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager...Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); UsbManager...usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice map = usbManager.getDeviceList
import usb from '@ohos.usbManager';// 获取设备列表。...import usb from '@ohos.usbManager';import { BusinessError } from '@ohos.base';let deviceName : string...import usb from '@ohos.usbManager';import { BusinessError } from '@ohos.base';/*读取数据,在device信息中选取对应数据接收的
Intent.ACTION_USER_INITIALIZE // 时区广播 Intent.ACTION_TIMEZONE_CHANGED // 语言区域 Intent.ACTION_LOCALE_CHANGED // USB UsbManager.ACTION_USB_ACCESSORY_ATTACHED...UsbManager.ACTION_USB_ACCESSORY_DETACHED UsbManager.ACTION_USB_DEVICE_ATTACHED UsbManager.ACTION_USB_DEVICE_DETACHED
/** Usb相关 UsbManager.ACTION_USB_ACCESSORY_ATTACHED UsbManager.ACTION_USB_ACCESSORY_DETACHED UsbManager.ACTION_USB_DEVICE_ATTACHED...UsbManager.ACTION_USB_DEVICE_DETACHED */ "保留原因:如果应用需要了解这些 USB 相关事件的信息,目前尚未找到能够替代注册广播的可行方案" /** 蓝牙状态相关
extrasHolder.set(extras); registerUsbPermissionBroadcastReceiver(); // Get UsbManager...UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); //Get the...private void openUsbDevice(UsbDevice device, Bundle extras) throws IOException { //从Android获取UsbManager...--- Get UsbManager from Android....UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE); //找到第一个可用的驱动程序
interface的实际运行流程,分析如下: 1)系统开机时,kernel启动init进程启动zygote启动孵化出SystemServer进程USB Service等一系列Service启动UsbManager...4.4 MTP传输启动流程代码分析 在"PC和Android设备建立MTP连接"后,UsbManager向MtpReceiver发送广播,接着MtpReceiver会启动MtpService,MtpService
接着它需要从UsbManager中查询USB的链接状态,MTP的设置信息和PTP的设置信息。
TRANSMIT_IR 或者请求运行时权限 BLUETOOTH_CONNECT or BLUETOOTH_ADVERTISE or BLUETOOTH_SCAN or UWB_RANGING 或者调用 UsbManager.requestPermission
领取专属 10元无门槛券
手把手带您无忧上云