1

PDFを開こうとしましたが、ボタンを押しても何も起こりません。私の間違いはどこですか?

OnClickListener oclBt2 = new OnClickListener(){
            public void onClick(View v) {
                File file = new File("http://testserv1.p.ht/1/ksu016.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);
                startActivity(intent);   
                try {
                    startActivity(intent);
                    } 
                catch (ActivityNotFoundException e) {
                     e.printStackTrace();
                    }
                }
            }
        };

コードを修正しましたが、再び機能しません:(ボタンを押すと、ウィンドウが表示されます(申し訳ありませんが、私の評判では画像を投稿できません)

OnClickListener oclBt2 = new OnClickListener(){
            public void onClick(View v) {
                Uri path = Uri.parse("http://testserv1.p.ht/1/ksu016.pdf");
                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) {               
                mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url=http://hostforandroid.elitno.net/pdf-test.pdf" );
                setContentView(mWebView);
                }               
            }
        };
4

1 に答える 1

1

まず、URLFileではなく、ローカル ファイル用です。URLへのポイントを取得するためにhttp使用します。Uri.parse("http://testserv1.p.ht/1/ksu016.pdf");Urihttp

第 2 に、HTTP URL から直接ダウンロードするように設定された PDF ビューアがない場合があります。DownloadManager互換性を高めるために、(独自の HTTP クライアント コードを使用して) 最初に PDF をダウンロードしてから、ローカルの PDF ファイルを表示するように手配できます。

于 2013-06-06T15:40:12.590 に答える