Android-Code to Implement PDF Viewer

后端 未结 2 1537
旧时难觅i
旧时难觅i 2021-02-04 22:22

Here i need to use Pdf-Viewer in my app.i took many API as a reference but still stucking up in viewing Pdf files from SDCARD. here my code

`First.java<

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 23:01

    you can open pdf on google doc

        WebView webviewer = new WebView(this);
        webviewer.getSettings().setJavaScriptEnabled(true);
        webviewer.getSettings().setPluginsEnabled(true);
        setContentView(webviewer);
    
        webviewer.loadUrl("http://docs.google.com/gview?embedded=true&url=PDF_url/fileName.pdf");
        setContentView(webviewer);
    

    To open the PDF in application like quick pdf or adobe pdf reader:

        Uri path = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    

提交回复
热议问题