Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you request MANAGE_EXTERNAL_STORAGE permission in Android?

Tags:

android

From Android Docs, https://developer.android.com/training/data-storage/manage-all-files#all-files-access

"An app can request All files access from the user by doing the following:

Declare the MANAGE_EXTERNAL_STORAGE permission in the manifest.

Use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files."

What I've tried

The only way I know how to request permissions is with ActivityCompat. I've tried:

ActivityCompat.requestPermissions(this, new String[]{Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION},1);

and

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.MANAGE_EXTERNAL_STORAGE},1);

Neither of which do anything.

The Android docs are extensive but not exactly the most welcoming for newcomers. I understand intents, and know they can be used to switch between activities, but I don't know what an "intent action" is and how it can be used to request permissions

like image 330
Chris A Avatar asked Jan 24 '21 22:01

Chris A


People also ask

How do I get storage permission in Android 11?

On the Settings > Privacy > Permission manager > Files and media page, each app that has the permission is listed under Allowed for all files. If your app targets Android 11, keep in mind that this access to "all files" is read-only.

How do I get permission denied on Android?

On your phone, open the Settings app. Permission manager. Tap a permission type. If you allowed or denied permission to any apps, you'll find them here.

What is MANAGE_EXTERNAL_STORAGE?

MANAGE_EXTERNAL_STORAGE. Backup and restore apps. App must have a need to automatically access multiple directories outside of its app-specific storage space for the purpose of backup and restore. Anti-virus apps. App's core purpose is to scan the device and provide anti-virus security features to the device user.


1 Answers

In Kotlin:

    val uri = Uri.parse("package:${BuildConfig.APPLICATION_ID}")

    startActivity(
      Intent(
        Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
        uri
      )
    )

(from this sample project)

You are probably used to an implicit Intent (Intent(this, SomeActivity::class.java)). The docs are asking you to use an explicit Intent, one with an action string and, in this case, a Uri. The Uri will have the package scheme and identify your app by its application ID.

That code snippet will start a system-supplied activity that, in theory, will let the user opt into granting your app the MANAGE_EXTERNAL_STORAGE permission.

The Android docs are extensive but not exactly the most welcoming for newcomers

You might wish to consider reading a book or taking a course. Any decent book or course will cover the concept of Intent actions.

like image 150
CommonsWare Avatar answered Oct 13 '22 01:10

CommonsWare