在Android应用程序打开PDF [英] Open PDF in android app

查看:168
本文介绍了在Android应用程序打开PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在哪里需要在设备中打开PDF文件的应用程序,

I am working on an application where need to open the pdf file in the device,

其实我已经得到了网页类似于大多数的例子在code。但是,事情是,我不能够打开文件和控制进入到异常直接的部分。

I have actually got the code on the web that is similar to most of the examples. But, the thing is that I am not able to open the file and the control goes to the "Exception" part directly.

下面是code如下:

public class MyPDFDemo extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)   
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    Button OpenPDF = (Button) findViewById(R.id.button);
    OpenPDF.setOnClickListener(new View.OnClickListener()
    { 
        public void onClick(View v) 
        {
            File pdfFile = new File("/sdcard/Determine_RGB_Codes_With_Powerpoint [PDF Library].pdf"); 
            if(pdfFile.exists()) 
            {
                Uri path = Uri.fromFile(pdfFile); 
                Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
                pdfIntent.setDataAndType(path, "application/pdf");
                pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                try
                {
                    startActivity(pdfIntent);
                }
                catch(ActivityNotFoundException e)
                {
                    Toast.makeText(MyPDFDemo.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
                }
            }

        }
    });

}

当我运行此code:我以前看到无应用程序可用于查看PDF。任何人都可以请我去查看PDF文件。

When I run this code : i used to see " No Application available to view pdf ". Can anyone please me to view the pdf file.

推荐答案

由于您的catch块有ActivityNotFoundException,就意味着你没有任何活动/应用程序,它可以读取一个应用程序/ PDF文件类型格式。安装从Android Market的任何PDF浏览器(的Adobe最近发布他们的),或者使用上面提到的开源PDF阅读器和您的问题将很可能会得到解决。

Since your catch block has ActivityNotFoundException, it means that you don't have any activity/application that can read a 'application/pdf' filetype format. Install any pdf viewer from the Android Market (Adobe recently release theirs), or else use the above mentioned open source pdf viewer and your problem will most probably will be solved.

<一个href="http://$c$c.google.com/p/apv/downloads/list">http://$c$c.google.com/p/apv/downloads/list

<一个href="https://market.android.com/details?id=cx.hell.android.pdfview&feature=search_result">https://market.android.com/details?id=cx.hell.android.pdfview&feature=search_result

当你开始的活动与您的特定参数,可以将搜索已注册的打开pdf格式的所有应用程序/活动/意图。既然你有没有在你的设备,你所得到的ActivityNotFoundException

When you start activity with your given params, it searches for all applications/Activities/Intents that are registered to open pdf format. Since you have none in your device, you are getting the ActivityNotFoundException

这篇关于在Android应用程序打开PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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