I already tried results from most of the questions but none worked for me.
I try accessing the WRITE_EXTERNAL_STORAGE permission using the PermissionAndroid.request method but it always returns never_ask_again as the result.
My requestFile:
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'External Storage Write Permission',
message: 'App needs write permission',
},
);
console.log(granted);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Start downloading
downloadFile();
console.log('Storage Permission Granted.');
} else {
// If permission denied then show alert
Alert.alert('Error', 'Storage Permission Not Granted');
}
} catch (err) {
// To handle permission related exception
console.log('++++' + err);
}
}
This is my AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application android:name=".MainApplication" android:usesCleartextTraffic="true" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
</application>
</manifest>
Please help me with fixing the issue.
Thanks in Advance.
Edit:
targetSDKVersion : 33 trying to test the app in Android 13
2
Answers
This is probably the expected result from the permission flow on Android.
Taken from https://developer.android.com/about/versions/11/privacy/permissions#dialog-visibility
react-native-permission has a nice flow chart of the permission flow: https://github.com/zoontek/react-native-permissions#android-flow
Well as you are checking your code in API level 33 (Android 13) , you have to skip to check and ask permission for WRITE_EXTERNAL_STORAGE from api level 33 as new android versions have introduced restrictions for storage access and provide secure way to access data . It is suggested always to write your data to app directory only(cache directory) if it not necessary to show data to user . For more information related changes of storage , go thought this documentation
Links:-
https://developer.android.com/about/versions/11/privacy/storage
https://developer.android.com/training/data-storage/shared/media
https://stackoverflow.com/a/74296799/5696047