0

我正在尝试打开一个位于 res/raw 文件夹中的 pdf 文档。单击按钮时,它会显示如下屏幕图片链接

不知道为什么会出现这样的画面……

请告诉我,谢谢...

请在下面找到我的代码

    Button MyRawBtn = (Button)findViewById(R.id.buttonId2);
            MyRawBtn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v)
                {
                    Toast.makeText(MainActivity.this,
                            "ImageButton (selector) is clicked!",
                        Toast.LENGTH_SHORT).show();

                    File pdfFile = new File("res/raw/sample.pdf");
                    Uri path = Uri.fromFile(pdfFile); 

                    //Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.sample);
                    //File file = new File(uri.toString());

                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setDataAndType(path,"application/pdf");
                        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                        startActivity(intent);
}
});
4

1 回答 1

0

请使用下面的 Stack Overflow Answer 的链接代码使用 PDFViewer.jar 库将 PDF 阅读到您的 android 应用程序中,如果您对此有任何疑问,请告诉我。

实现 PDF 阅读器的代码

于 2012-12-03T06:43:01.837 回答