While trying to upload a file from internal storage am getting an Exception for open failed: EACCES Denied
. I have added android:requestLegacyExternalStorage="true"
if (SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(getContext(),
READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(), new String[]{READ_EXTERNAL_STORAGE},
EXTERNAL_STORAGE_PERMISSION_CODE);
ActivityCompat.requestPermissions(getActivity(), new String[]{ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION},1);
requestPermission();
//startActivity(new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, Uri.parse("package:${BuildConfig.APPLICATION_ID}")));
return;
}
In Android 10 and 11, you've to use Scoped Storage to access files. But, if you set android:requestLegacyExternalStorage
to true
, then you can work with the previous methods of accessing storage in Android 10.
For Android 11, you've to set targetSDKVersion
as 29
, not 30
to make android:requestLegacyExternalStorage
work as mentioned in the below image, Reference - Storage updates in Android 11 .
So, in your build.gradle (app), set targetSdkVersion 29
or go withScoped Storage .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.