2012-12-03 65 views
0

我想打开一个PDF文档,它位于res/raw文件夹中。当点击按钮时,它显示如下屏幕image link打开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); 
} 
}); 
+0

是否使用PDFViewer.jar库? –

+0

@DipakKeshariya:我正在使用AndroidPdfViewer_1_0_1.apk – user198725878

+0

请看我的回答,如果它对你有帮助,那么请接受它。 –

回答

0

请使用以下堆栈溢出答案的链接代码阅读PDF使用PDFViewer.jar库到您的Android应用程序,如果您有任何疑问,然后告诉我。

Code to Implement a PDF Reader