简体   繁体   English

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

[英]Openning PDF within app. Not working. Help needed

Relatively new to this. 相对较新。 I have an issue of opening a pdf within the app itself. 我在应用本身中打开pdf时遇到问题。 I can do open urls and let the user surf within the app but I am having an issue with PDFs. 我可以打开网址,让用户在应用程序中浏览,但是PDF出现问题。 I am using docs.google.com/gview to do this but It is not working for some reasonI get an error from Google 414. Here is my code: 我正在使用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;
}

} }

ALL the links on the page are pdf. 页面上的所有链接均为pdf。 How do I fix this? 我该如何解决? Thanks in advance. 提前致谢。

414 is url too long. 414网址太长。 I think you have an infinite loop- your shouldOverrideUrlLoading is called each time you load the page. 我认为您有一个无限循环-每次加载页面时都会调用shouldOverrideUrlLoading。 It calls loadPage on a new, longer URL. 它在更长的新URL上调用loadPage。 This calls shouldOverrideUrlLoading again. 这将再次调用shouldOverrideUrlLoading。 This loops until you go over the size limit of a URL. 这将循环直到您超过URL的大小限制。 shouldOverrideUrlLoading should never call loadPage. shouldOverrideUrlLoading永远不要调用loadPage。 Instead it should return true if you want to override the URL, and false otherwise. 相反,如果要覆盖URL,则应返回true,否则返回false。 At the very least you should check and not call loadPage if the url starts with http://docs.google.com/gview 如果网址以http://docs.google.com/gview开头,则至少应检查并不要调用loadPage。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM