0

Android アプリケーションから PDF ファイルを開きたいと思います。インターネットで方法を検索しましたが、非常に簡単に思えますが、少なくとも私のモバイル (Sony XPeria P) では機能しません。

File file = ....

Intent intent = new Intent(Intent.ACTION_VIEW, 
                  Uri.fromFile (file));             
intent.setType("application/pdf");                  
startActivity(intent);

このコードが実行されると、ウィンドウが開き、PDF を表示するアプリケーションを選択するよう求められます。Adobe Reader を選択すると、ドキュメントが表示されずに開かれます。

私が間違っていることは何ですか?

4

2 に答える 2

1

これを試してください、それは私のために働いています

//PDF Viewer で PDF ファイルを開くメソッド

public void OpenPDFFile() {
    File pdfFile = new File(Environment.getExternalStorageDirectory(),"PdfFile.pdf");//File path
    if (pdfFile.exists()) //Checking for the file is exist or not
    {
        Uri path = Uri.fromFile(pdfFile);
        Intent objIntent = new Intent(Intent.ACTION_VIEW);
        objIntent.setDataAndType(path, "application/pdf");
        objIntent.setFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(objIntent);//Staring the pdf viewer
    }
}
于 2012-11-20T08:15:44.600 に答える