如何从android中的远程URL从我的应用程序打开pdf

时间:2011-06-30 06:37:34

标签: android

我想在远程网址的应用中打开PDF。请帮帮我。

 Uri path = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.wsa);
        final String googleDocsUrl = "http://docs.google.com/viewer?url=";

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(googleDocsUrl +path), "text/html");

感谢。

2 个答案:

答案 0 :(得分:1)

  WebView webView=(WebView)this.findViewById(R.id.WebView01);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setPluginsEnabled(true);
        webView.loadUrl("https://docs.google.com/viewer?url=http%3A%2F%2Fwww.eli.sdsu.edu%2Fcourses%2Ffall09%2Fcs696%2Fnotes%2FAndroid13Web.pdf");


        try {
            startActivity(intent);
        } 
        catch (ActivityNotFoundException e) {
            Toast.makeText(ReaderActivity.this, 
                "No Application Available to View PDF", 
                Toast.LENGTH_SHORT).show();
        }

看看它在我的代码中是否正常工作。 我希望它对你有所帮助。

答案 1 :(得分:-1)

你必须提供mime类型作为application / pdf

尝试使用以下代码

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://14.140.41.194/monali/i.pdf"), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);