今、Androidアプリケーションを実行しています.SDcard.Iからファイルを読み込む必要があります。私のemulater.AndにAdobe Readerをインストールしました。次のコードを使ってsdcardからファイルを実行しました。プログラムでPDFファイルを読み込み中にエラーが発生しました
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("/sdcard/samp.pdf"), "application/pdf");
try{
startActivity(intent);
}
catch (ActivityNotFoundException e) {
System.out.println("5");
// No application to view, ask to download one
System.out.println("hai");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("Download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent
.setData(Uri
.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
私は、「ファイルを開くことができませんでした」取得しています私は自分のアプリケーションを実行していたときにsdcard.Butにsample.pdfが名前のPDFファイルを挿入します。しかし、私は手動でエミュレータからpdfを開くことができます。私が解決策を見つけるのを助けてください。
こんにちは、私は解決策を得ました。私は今、その作業を
File file = new File("/sdcard/sample.pdf");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
intent.setDataAndType(Uri.parse("/sdcard/samp.pdf"), "application/pdf");
と追加を削除しました。しかし、今私は、資産フォルダにsample.pdfフォルダを置き、次のコードを書いています。
File file = new File("android.resource://com.pdftest/assets/sample");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
と私はファイルパスではない有効なメッセージを取得...
私はいくつかの変更を行ったA及び今その作業... I removeintent.setDataAndType(Uri.parse( "/ SDカード/ samp.pdf ")、" application/pdf ");ファイルfile = new File( "/ sdcard/sample.pdf")を追加します。 Uri uri = Uri.fromFile(file); intent.setDataAndType(uri、 "application/pdf"); – sarath
こんにちは..それはsdcardのために働いていますが、資産フォルダに入れたファイルではありません。資産フォルダから同じファイルを読み込む方法。私はFile file = new File( "/ sdcard/sample.pdf"); Uri uri = Uri.fromFile(file); intent.setDataAndType(uri、 "application/pdf");しかし、ファイルパスが見つかりません – sarath
ya..i私のファイルをassetsフォルダに入れて、File file = new File( "android.resource://com.pdftest/assets/sample"); ..と書くが、見つかった... – sarath