2

私はAndroidプログラミングに不慣れで、Androidでアプリケーションを開発して、アプリのサーバーからPDFファイルを開きます。それについてはわかりません。だから私を助けてください。どうすればこれを行うことができますか?

前もって感謝します。

4

3 に答える 3

7

アプリケーションで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");
于 2012-07-30T09:31:01.607 に答える
3
   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" >
于 2012-07-30T09:32:19.330 に答える
0
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-07-30T10:46:39.390 に答える