react-native: Android 13 permission issue
Description
Hi,
I am unable to request permission for storage. It always returns {"android.permission.READ_EXTERNAL_STORAGE": "never_ask_again", "android.permission.WRITE_EXTERNAL_STORAGE": "never_ask_again"}
whenever I try to ask for permission. I tried everything but still the the permission is not allowed on Android 13, sdk 33.
Your help will be really appreciated.
Thank you.
Version
0.70.6
Output of npx react-native info
System: OS: macOS 13.0 CPU: (12) x64 Intel® Core™ i7-8850H CPU @ 2.60GHz Memory: 332.93 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node Yarn: 1.22.19 - ~/node_modules/.bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v16.17.1/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.16 - /usr/bin/javac npmPackages: @react-native-community/cli: ^9.0.0 => 9.0.0 react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
-
declare permission issue in manifest file
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
request for storage permission
const permission = [ PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, ]; const granted = await PermissionsAndroid.requestMultiple(permission);
-
result
{"android.permission.READ_EXTERNAL_STORAGE": "never_ask_again", "android.permission.WRITE_EXTERNAL_STORAGE": "never_ask_again"}
Snack, code example, screenshot, or link to a repository
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 18
I am facing the same issue.
let deviceVersion = DeviceInfo.getSystemVersion(); let granted = PermissionsAndroid.RESULTS.DENIED; if(deviceVersion >= 13){ granted = PermissionsAndroid.RESULTS.GRANTED; }else{ granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE ); }
fixes the issue for me. as Android version 13 no permission is needed.
@Ghoral , turns out that if you targed sdk 33 you dont need to ask permission. Here is code in AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
Hello, does this apply to all android versions or for lower android versions i still need to ask for permission ?
I was able to fix mine, you should do it this way, i am still testing across different tester devices.
Kind of
Maybe target sdk 33 is needed as well
You dont need to add permission specifically.
If it is for notification you need to have targetSdkVersion = 33 (at least) and change your code.
` import messaging from ‘@react-native-firebase/messaging’; await messaging().requestPermission();
for other permissions follow documentation.
@A-Vijay - How can use below code for document picker(react-native-document-picker) in Android 13. let deviceVersion = DeviceInfo.getSystemVersion(); let granted = PermissionsAndroid.RESULTS.DENIED; if(deviceVersion >= 13){ granted = PermissionsAndroid.RESULTS.GRANTED; }else{ granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE ); }
yes In android 13 no permission is needed