相关疑难解决方法(0)

如何在Android中呈现PDF

在我的应用程序中,我将收到一个字节流并将其转换为手机内存中的pdf文件.如何将其呈现为pdf?并在活动中展示它?

java pdf android

78
推荐指数
4
解决办法
8万
查看次数

在Android应用中打开PDF

我正在开发一个需要在设备中打开pdf文件的应用程序,

我实际上在网上获得了与大多数示例类似的代码.但是,问题是我无法打开文件,控件直接进入"异常"部分.

以下是代码:

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(); 
                }
            }

        }
    });

} …
Run Code Online (Sandbox Code Playgroud)

pdf android

16
推荐指数
1
解决办法
4万
查看次数

标签 统计

android ×2

pdf ×2

java ×1