在应用内打开PDF。不工作。需要帮助

时间:2014-03-16 00:49:50

标签: java android pdf

相对较新。我有一个问题,即在应用程序内打开pdf。我可以打开网址,让用户在应用程序内浏览,但我遇到了PDF问题。我使用docs.google.com/gview执行此操作但由于某种原因我无法使用Google 414收到错误。这是我的代码:

public class MainActivity extends Activity {




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);





    WebView theWebPage = new WebView(this);
       setContentView(theWebPage);

       theWebPage.getSettings().setBuiltInZoomControls(true);
       theWebPage.zoomIn();

     theWebPage.loadUrl("http://www.example.com");


     theWebPage.getSettings().setJavaScriptEnabled(true);



   //theWebPage.getSettings().setPluginsEnabled(true);


       theWebPage.setWebViewClient(new WebViewClient() {
           @Override
           public boolean shouldOverrideUrlLoading(WebView view, String url) {


               String url2 = "http://docs.google.com/gview?embedded=true&url=" + url;

             view.loadUrl(url2);

               //view.loadUrl(url);

               return false;
           }
       });





}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

页面上的所有链接均为pdf。我该如何解决?提前谢谢。

2 个答案:

答案 0 :(得分:0)

414是网址太长。我认为你有一个无限循环 - 每次加载页面时都会调用shouldOverrideUrlLoading。它在一个新的更长的URL上调用loadPage。这会再次调用shouldOverrideUrlLoading。这将循环,直到您超过URL的大小限制。 shouldOverrideUrlLoading永远不应该调用loadPage。相反,如果要覆盖URL,则应返回true,否则返回false。如果网址以http://docs.google.com/gview

开头,您至少应该检查并不要调用loadPage

答案 1 :(得分:0)

您可以尝试使用此库在应用程序中显示PDF文件 https://github.com/jblough/Android-Pdf-Viewer-Library

相关问题