skip to Main Content

I am building a react native app. I am running a pixel 7 virtual device and I am trying to request permission to access the phones file system to download an image from the app however I am not seeing the request window pop up and the permission is set to never_ask_afain even though I have never set it to this. I have reinstalled the app, tried a different virtual device etc etc

const requestStoragePermission = async () => {
    if (Platform.OS === 'android') {
      try {
        console.log(Platform.OS);
        const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            {
              title: 'Storage Permission',
              message: 'App needs access to your storage to save the QR code',
              buttonNeutral: 'Ask Me Later',
              buttonNegative: 'Cancel',
              buttonPositive: 'OK',
            },
        );
        console.log(`Results... ${granted}`)
        return granted === PermissionsAndroid.RESULTS.GRANTED;
      } catch (err) {
        console.warn(err);
        return false;
      }
    } else {
      return true; // iOS does not need this permission
    }
  };

This is the output to my log

 android
 LOG  Results... never_ask_again

here is my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <application android:name=".MainApplication" 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"/>
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="inethi"/>
      </intent-filter>
    </activity>
  </application>
</manifest>

my package.json file:

{
  "name": "inethi",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-keycloak/native": "^0.6.4",
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-camera-roll/camera-roll": "^5.6.0",
    "@react-native-clipboard/clipboard": "^1.14.1",
    "@react-native-picker/picker": "^2.7.5",
    "axios": "^1.6.8",
    "qrcode": "^1.5.4",
    "react": "18.2.0",
    "react-native": "0.73.4",
    "react-native-blob-util": "^0.19.11",
    "react-native-document-picker": "^9.1.1",
    "react-native-fs": "^2.20.0",
    "react-native-images-to-pdf": "^0.2.1",
    "react-native-paper": "^5.12.3",
    "react-native-pdf": "^6.7.5",
    "react-native-permissions": "^4.1.5",
    "react-native-qrcode-svg": "^6.3.2",
    "react-native-safe-area-context": "^4.9.0",
    "react-native-svg": "^15.5.0",
    "react-native-vector-icons": "^10.0.3",
    "react-native-webview": "^13.8.1",
    "react-router-native": "^6.22.1",
    "rn-fetch-blob": "^0.12.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

I am using react native v0.73.4.

I expect the permission window to appear and ask the user if they will grant permissions however it NEVER does

2

Answers


  1. Chosen as BEST ANSWER

    Here is the answer to the question... PermissionAndroid.request() always returns never_ask_again without any prompt. React Native.

    You do not need to ask for this if you are using a version of the android API >33


  2. Steps to resolve:
    Check Permission Before Requesting:

    Ensure you are checking the permission status before requesting it. If the permission is already set to never_ask_again, you might need to direct the user to the app settings to manually enable it.

    Modify Your Code to Handle never_ask_again:

    Clear App Data or Reset Permissions:

    If you keep encountering the never_ask_again status, try clearing the app data or resetting the app permissions through the device settings.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search