Kar*_* Ve 8 android intentfilter android-intent android-file
我正在我的 android 应用程序中处理 pdf 文件。在警报对话框中按“是”应该会在默认文件管理器应用程序中打开 pdf 文件位置。
我试过这个,但它总是打开一个选择器。即使它(ES文件资源管理器)打开“选择路径”对话框而不是应用程序中的文件夹作为访问文件夹的正常方式。
那么,是否可以在“默认文件管理器”中直接打开文件夹的内容?或者可以使用选择器打开,在选择 pdf 文件时,它应该从所选的应用程序中显示 pdf 文件选择器?。
以下是我为实现这一目标所做的尝试。
public void openFolder(String filePath)
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(filePath.substring(0, filePath.lastIndexOf("/")));
intent.setDataAndType(uri, "*/*");//tried with application/pdf and file/*
intent.addCategory(Intent.CATEGORY_OPENABLE);
PackageManager pm = context.getPackageManager();
List<ResolveInfo> apps =
pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (apps.size() > 0)
startActivity(intent);//Intent.createChooser(intent, "Open folder"
}
Run Code Online (Sandbox Code Playgroud)
编辑 我也试过 ACTION_PICK 。它定向到默认文件管理器的特定文件夹。但是从那里选择文件不会打开选择器(pdf 查看器列表对话框)。
| 归档时间: |
|
| 查看次数: |
8611 次 |
| 最近记录: |