Closed auloma04 closed 9 months ago
Hello. I am encountering an error using the library. I am trying to call device.init() after having requested permissions to the user, but it ejects the device without throwing an error.
for(UsbMassStorageDevice device: devices) { BroadcastReceiver usbReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { synchronized (this) { if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) { Log.d("MY APPLICATION storage", "Permission granted"); try { device.init(); } catch (IOException e) { tvUsb.setText(e.getMessage()); } } else { tvUsb.setText("Permission denied"); } } } }; IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); registerReceiver(usbReceiver, filter); PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); usbManager.requestPermission(device.getUsbDevice(), permissionIntent); }
manifest:
<application android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.MyApplication" tools:targetApi="31"> <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <intent-filter> <action android:name="com.emteria.usbpermissions.USB_PERMISSION" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.usb.host" /> <uses-permission android:name="android.permission.USB_PERMISSION" />
Here a screenshot of the logcat: adb logcat | grep -i storage We can see the device ejecting directly after calling device.init()
Running on Android 8 / API 27. Has somebody encountered a similar issue ?
@magnusja maybe a mistake from my side ?
Problem solved: was using an older version through mjdev
Hello. I am encountering an error using the library. I am trying to call device.init() after having requested permissions to the user, but it ejects the device without throwing an error.
manifest:
Here a screenshot of the logcat: adb logcat | grep -i storage We can see the device ejecting directly after calling device.init()
Running on Android 8 / API 27. Has somebody encountered a similar issue ?
@magnusja maybe a mistake from my side ?