List of usage examples for android.hardware.usb UsbManager EXTRA_DEVICE
String EXTRA_DEVICE
To view the source code for android.hardware.usb UsbManager EXTRA_DEVICE.
Click Source Link
From source file:com.github.mjdev.libaums.usbfileman.MainActivity.java
/** * Searches for connected mass storage devices, and initializes them if it * could find some./*from w w w. jav a2s . c o m*/ */ private void discoverDevice() { UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); UsbMassStorageDevice[] devices = UsbMassStorageDevice.getMassStorageDevices(this); if (devices.length == 0) { Log.w(TAG, "no device found!"); android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("No device"); listView.setAdapter(null); return; } // we only use the first device device = devices[0]; UsbDevice usbDevice = (UsbDevice) getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE); if (usbDevice != null && usbManager.hasPermission(usbDevice)) { Log.d(TAG, "received usb device via intent"); // requesting permission is not needed in this case setupDevice(); } else { // first request permission from user to communicate with the // underlying // UsbDevice PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); usbManager.requestPermission(device.getUsbDevice(), permissionIntent); } }