Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the "internal storage" option in an ActionOpenDocument intent by default

I need the user to select a file of a custom filetype that they've dragged onto their android device from windows file explorer, but the internal storage option isn't available by default.

When I launch the intent using this:

var libraryIntent = new Intent(Intent.ActionOpenDocument);
libraryIntent.SetType("application/*");
_activity.StartActivityForResult(libraryIntent, (int)ActivityRequestCode.ImportFeatureCodeLibrary);

Android OS (5.1 and 6.0) shows the following screen:

enter image description here

The user has to know to go to the button in the top right and select the option to show internal file storage:

enter image description here

They have to click the hamburger again and only then does it show up in the list:

enter image description here

Is there a way to have this option show up in the list by default, or even better to have the user dropped into the "internal storage" file picker?

like image 562
Slepz Avatar asked Jan 10 '18 18:01

Slepz


People also ask

How do I enable scoped storage on Android?

To enable scoped storage in your app, regardless of your app's target SDK version and manifest flag values, enable the following app compatibility flags: DEFAULT_SCOPED_STORAGE (enabled for all apps by default) FORCE_ENABLE_SCOPED_STORAGE (disabled for all apps by default)

How to use action_ Open_ document?

So, you use ACTION_OPEN_DOCUMENT to request that the user choose a document. You take the Uri that you get and eventually you call openOutputStream() on a ContentResolver , passing in that Uri . You then try to write content out to that stream, to be able to store that content in the user-chosen document.

What is scoped storage and how to implement?

Scoped storage is the default behavior in Android 10 and 11. Once the app has been whitelisted on Google Play, the user can be asked for special permission. The Media Store in Android 11 has been upgraded. The user may bulk delete/edit media files, which was not possible in Android 10.


1 Answers

You can add an extra to the intent :

libraryIntent.PutExtra("android.content.extra.SHOW_ADVANCED", true);

As far as I know it's an undocumented extra, but it seams to work from API 19 to at least 26

like image 126
bwt Avatar answered Oct 03 '22 22:10

bwt