我想为可以返回任何类型文件的应用启动intentchooser
目前我使用(我从Android电子邮件源代码中复制了文件附件)
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "File");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
Run Code Online (Sandbox Code Playgroud)
但它只在我的Galaxy S2上显示"画廊"和"音乐播放器".此设备上有一个文件浏览器,我希望它出现在列表中.我还希望相机应用程序显示在列表中,以便用户可以拍摄照片并通过我的应用程序发送.如果我安装Astro文件管理器,它也会响应这个意图.我的客户只是Galaxy SII所有者,我不想强迫他们安装Astro文件管理器,因为他们已经拥有一个基本但足够的文件管理器.
知道如何实现这一目标吗?我很确定我已经看到默认文件管理器出现在这样的菜单中以选择文件,但我不记得在哪个应用程序中.
我正在使用第三方文件管理器从文件系统中选择一个文件(在我的情况下为PDF).
这是我启动活动的方式:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(getString(R.string.app_pdf_mime_type));
intent.addCategory(Intent.CATEGORY_OPENABLE);
String chooserName = getString(R.string.Browse);
Intent chooser = Intent.createChooser(intent, chooserName);
startActivityForResult(chooser, ActivityRequests.BROWSE);
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的onActivityResult:
Uri uri = data.getData();
if (uri != null) {
if (uri.toString().startsWith("file:")) {
fileName = uri.getPath();
} else { // uri.startsWith("content:")
Cursor c = getContentResolver().query(uri, null, null, null, null);
if (c != null && c.moveToFirst()) {
int id = c.getColumnIndex(Images.Media.DATA);
if (id != -1) {
fileName = c.getString(id);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
代码片段来自Open Intents文件管理器说明,网址为: …
如何从现有的URI中保存媒体文件(比如.mp3),这是我从隐含意图获得的?