作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
最佳答案
您可以启动一个 Intent,允许用户使用以下代码选择打开 PDF 的应用程序,该代码适用于任何文件和 mime 类型。如果用户没有可以打开它的应用程序,您可以显示错误或执行您需要执行的任何其他操作。
请注意,该文件必须是全局可读的,因此如果它在内部存储中,则必须如此标记,否则它必须在外部存储中。
private void openFile(File f, String mimeType)
{
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
// using the packagemanager to query is faster than trying startActivity
// and catching the activity not found exception, which causes a stack unwind.
List<ResolveInfo> resolved = getPackageManager().queryIntentActivities(viewIntent, 0);
if(resolved != null && resolved.size() > 0)
{
startActivity(viewIntent);
}
else
{
// notify the user they can't open it.
}
}
关于android - 有没有办法使用谷歌文档读取本地pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5113883/
我是一名优秀的程序员,十分优秀!