+ private static final String ACTION_USB_PERMISSION =
+ "com.android.example.USB_PERMISSION";
+ private final BroadcastReceiver mUsbReceiver = 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, true)) {
+ if(device != null){
+ Log.e(TAG, "extra permission granted");
+ //call method to set up device communication
+
+
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ Log.e("device","MyThread3");//bhw
+ UsbDeviceConnection connection = usbManager.openDevice(usbCamera);
+ int fd = connection.getFileDescriptor();//获取文件描述符
+ ffmpeg.test(fd);
+ Log.e("device","MyThread3 "+fd);
+ }
+ }).start();
+
+ }
+ }
+ else {
+ Log.e(TAG, "permission denied for device. " + device);
+ }
+ }
+ } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)){
+ UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+ if (device != null){
+ Log.e(TAG, "==== device out");
+ }
+ } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
+ Log.e(TAG, "==== device in =====");
+ }
+ }
+ };
+
+
+