My phone is a Samsung A32 5G ( SM-A326B/DS). Android 12, native ROM, SDK 31.
I need to read files from OTG USB dongle from 2 apps :
- My app which is an installer. It install some APK and restore some data external SD card or OTG USB Device.
- Termux app, dowloaded from github and modified to request the right.
The manifest includes :
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
To request in java code I tried 2 methods :
First method :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager()) {
CTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION");
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
String name = getPackageName();
Uri uri = Uri.fromParts("package", name, null);
intent.setData(uri);
startActivity(intent);
}
}
Second method :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!getPackageManager().canRequestPackageInstalls()) {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:" + BuildConfig.APPLICATION_ID));
startActivityForResult(intent, 501);
}
}
In two apps, the problem is that it the authorization does not take effect inside the Activity which asked the authorization. Even if I end my Activity with finish() and start again my App, I have not the access. But if I kill my app with task manager and start the app, the I get the right. But when I kill my app with the task manage and start it again, then I access the USB dongle.
In both app, to access the ISB Key I use linux commands.
- With
mountcommand I check that the USB Dongle is seen by Android. - With
USBPATH=$(grep -E "^[^ ]+ /mnt/media_rw/[A-Z0-9]{4}-[A-Z0-9]{4} " /proc/mounts | cut -d' ' -f2)I get the path of the dongle - With
ls $USBPATHI see that I have not the right, even after MANAGE_EXTERNAL_STORAGE has been granted, because ls returns "permission denied".
You have no read access to /mnt/media_rw.
All files access has no effect on it.