【问题标题】:Android : how to open pdf file from server in android [closed]Android:如何在 android 中从服务器打开 pdf 文件 [关闭]
【发布时间】:2012-07-27 22:51:12
【问题描述】:

我是 android 编程新手,我正在用 android 开发一个应用程序,以便从我的应用程序中的服务器打开 PDF 文件。我对此一无所知。所以请帮助我。我该怎么做?

提前致谢。

【问题讨论】:

标签: android pdf iframe pdf-generation


【解决方案1】:

您必须尝试使用​​此代码在您的应用程序中打开 pdf 文件..

WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");

【讨论】:

    【解决方案2】:
       String pdf = "http://www.xyzwebsite.com/yourfile.pdf"; //YOUR URL TO PDF
       String googleDocsUrl = "http://docs.google.com/viewer?url="+ pdfurl;
       Intent intent = new Intent(Intent.ACTION_VIEW);
       intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
       startActivity(intent);
    

    将此权限添加到清单文件

    <uses-permission android:name="android.permission.INTERNET" >
    

    【讨论】:

      【解决方案3】:
      File file = new File("/sdcard/example.pdf");
      
                      if (file.exists()) {
                          Uri path = Uri.fromFile(file);
                          Intent intent = new Intent(Intent.ACTION_VIEW);
                          intent.setDataAndType(path, "application/pdf");
                          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      
                          try {
                              startActivity(intent);
                          } 
                          catch (ActivityNotFoundException e) {
                              Toast.makeText(OpenPdf.this, 
                                  "No Application Available to View PDF", 
                                  Toast.LENGTH_SHORT).show();
                                String pdf = "http://www.xyzwebsite.com/yourfile.pdf"; //YOUR URL TO PDF
                                String googleDocsUrl = "http://docs.google.com/viewer?url="+ pdfurl;
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
                                startActivity(intent);
      
      
                          }
                      }
                  }
      

      【讨论】:

        猜你喜欢
        • 2012-01-24
        • 2014-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多