Android-未找到用于处理Intent的活动{act = android.intent.action.VIEW-尝试打开PDF文件 [英] Android - No Activity found to handle Intent { act=android.intent.action.VIEW - Trying to open a PDF File

查看:1008
本文介绍了Android-未找到用于处理Intent的活动{act = android.intent.action.VIEW-尝试打开PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了很多搜索以找到解决方案,但仍然找不到任何

I searched a lot to find a solution , but still can't find any

我正在尝试在Android应用程序中打开PDF文件

I am trying to open a PDF file in my android application

这是我的代码:

try 
    {
        File file = new File(Environment.getExternalStorageDirectory()+"/pdf/Read.pdf");
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        Log.d("CheckingURI", uri.toString());
        intent.setDataAndType(uri, "application/pdf");
        startActivity(intent);
    } 
    catch (Exception e) 
    {
        Log.d("OpenPDFError", e.getMessage());
    }

Tomcat日志表明没有活动可以处理意图

The Tomcat Log implies that there is no activity to handle the intent

09-19 19:55:02.938: D/CheckingURI(30483): file:///mnt/sdcard/pdf/Read.pdf
09-19 19:55:02.948: D/OpenPDFError(30483): No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/pdf/Read.pdf typ=application/pdf }

还有其他方法可以执行此操作吗?或者可以使用其他默认的PDF查看器打开PDF文件吗?如果是,怎么办?

Is there any other way to do this or can i open the PDF file with another default PDF viewer? If yes, how?

更新: 主要问题是我没有在模拟器上安装PDF查看器应用程序...

Update : the main problem was that i did not install a PDF viewer application on my emulator ...

推荐答案

尝试以下方法:

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/pdf/Read.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

注意:仅当您预先安装了PDF Viewer时,以上方法才有效.如果没有,则需要安装PDF Viewer.

CAVEAT: The above method only work if you have a pre-installed PDF Viewer. If not, you need to install a PDF Viewer.

这篇关于Android-未找到用于处理Intent的活动{act = android.intent.action.VIEW-尝试打开PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆