1

重複の可能性:
AndroidでPDFを開く

AndroidアプリケーションからAdobeReaderでPDFファイルを開きたいのですが。

/ mnt / sdcardにtest.pdfというPDFファイルがあり、次のコードを使用しています。

file = new File ("/mnt/sdcard/test.pdf");

if (file.exists())
{
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
    intent.setType("application/pdf");
    intent.setPackage("com.adobe.reader");          
    startActivity(intent);              
}

このコードを実行するとAdobeReaderが開きますが、ファイルは開きません。ファイルは有効です。

何が問題ですか?

4

2 に答える 2

6

これを試して。

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);
于 2012-11-20T08:55:19.823 に答える
1

このコードを試してください

File file=new File("/mnt/sdcard/test.pdf");
if(file.exists())
{
    Uri path=Uri.fromFile(file);
    Intent intent=new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");

    try
    {
        startActivity(intent);
    }
    catch(ActivityNotFoundException e)
    {
        Toast.makeText(TestActivity.this, "No software for PDF", Toast.LENGTH_SHORT).show();
    }
}
于 2012-11-20T08:51:58.477 に答える