Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

android - How to show more providers with ACTION_OPEN_DOCUMENT

I want to use the android system dialog provided as part of the Storage Access Framework to open a file. I do this with

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
startActivityForResult(intent, EDIT_REQUEST);

and then handle the returned URI in onActivityResult().

The problem is that, in the resulting menu, I get far less content providers than I expected. Only Google Drive and Downloads (see left screen shot below). Others, like Dropbox, Solid Explorer,... are not show.

I suspect the reason is that these apps simply don't set the necessary intent filter to show up in this list.

However, other apps, for example Kaiten Mail or Chrome, somehow manage to show the system dialog with fully implemented content providers at the top of the list and then others, like Dropbox and Solid Explorer, below, separated by a thin bar (see the right screen shot).

How can I get this behavior?

Comparison of the behavior I get (left) and the one I want (right)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use 'ACTION_GET_CONTENT:

Intent intent = new Intent(Intent. ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, EDIT_REQUEST);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...