Home:ALL Converter>Android: Storage and camera permission

Android: Storage and camera permission

Ask Time:2022-01-15T02:25:05         Author:NightCoder101

Json Formatter

My question is specific to Android 11. Since Android 11, we now have concept of scoped storage. I have read many answers on SO but I am still confused.

Few specs of my project:

        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"

WHAT I UNDERSTAND FROM SCOPED STORAGE IN ANDROID 11:

Earlier any app can read/write anywhere in the filesystem. Now, an app can read/write only in its private directory (excluding a few 'generally available' directories like DCIM). Is my understanding correct? (Question 1)

Private directory being : Android/data/com.myappname/files/

THERE ARE 2 SCENARIOS IN MY APP:

  1. My app creates a file if its not created and then later reads it. I hardcoded now (for Android 11) the full path in my react native code: Android/data/com.myappname/files/myfilename. It is now working fine in android 11. Now my question is: Do I need to mention READ/WRITE_EXTERNAL_STORAGE in AndroidManifest.xml file?(Question 2) Secondly, do I need to ask user using dialog prompt in the app for any (storage) permission? (Question 3)

  2. My app is using camera and gallery. For that I have only provided CAMERA permission in AndroidManifest.xml. Is it sufficient? What line should I add for reading from gallery? (Question 4)

Permissions from my AndroidManifest.xml is below:

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" tools:node="remove" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" tools:node="remove" />
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" tools:node="remove" />
    <uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" tools:node="remove" />
    <uses-permission android:name="android.permission.USE_BIOMETRIC" tools:node="remove" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" tools:node="remove" />

Author:NightCoder101,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/70715018/android-storage-and-camera-permission
Malik Bilal :

\nFor app-specific storage you don't need any permission to read and write.\n\nIf you want to get some permission from the user it's good to display a dialog as a consent explaining why you need this permission.\n\nFor Gallery below android 10 you need the android.permission READ_EXTERNAL_STORAGE permission. For the Camera yes you only need to add <uses-permission android:name="android.permission.CAMERA" />. You can add this line also <uses-feature android:name="android.hardware.camera.any" /> for Play Store.\n\n",
2022-01-14T19:13:59
yy