RxPermissions
RxPermissions copied to clipboard
How to request USB Permission ?
old method:
/**
* 获取Usb权限
* @param context
* @param usbManager
*/
private void tryGetUsbPermission(Context context, UsbManager usbManager, UsbDevice device, UsbInterface intf){
Log.i(LOG_TAG, "Printer#tryGetUsbPermission");
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
// context.registerReceiver(mUsbPermissionActionReceiver, filter);
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
if(usbManager.hasPermission(device)){
//if has already got permission, just goto connect it
//that means: user has choose yes for your previously popup window asking for grant perssion for this usb device
//and also choose option: not ask again
afterGetUsbPermission(context, usbManager, device, intf);
}else{
//this line will let android popup window, ask user whether to allow this app to have permission to operate this usb device
usbManager.requestPermission(device, mPermissionIntent);
}
}