сейчас я делаю приложение для Android. Мне нужно прочитать файл с sdcard.I установлен в Adobe Reader. Я использовал следующий код для запуска файла из SD карты.чтение 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();
}
Я вставил в формате PDF с именем sample.pdf в sdcard.But, когда я бегу мое приложение я получаю «файл не может быть открыт». Но я могу открыть pdf вручную из emulater. Пожалуйста, помогите мне найти решение.
Привет, у меня есть решение. Я удалил intent.setDataAndType(Uri.parse("/sdcard/samp.pdf"), "application/pdf");
и добавить
File file = new File("/sdcard/sample.pdf");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
в настоящее время его работы. Но теперь я поместил папку sample.pdf в папку моих ресурсов и напишу следующий код.
File file = new File("android.resource://com.pdftest/assets/sample");
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
и я получаю путь к файлу не правильное сообщение ...
Я сделал некоторые изменения Aand теперь его рабочий ... Я removeintent.setDataAndType (Uri.parse ("/ SDCard/samp.pdf ")," application/pdf "); и добавьте File file = new File ("/ sdcard/sample.pdf"); Uri uri = Uri.fromFile (файл); intent.setDataAndType (uri, "application/pdf"); – sarath
Привет .. Теперь его работа для sdcard, но не для файла, который я вложил в папку с ресурсами. Как прочитать тот же файл из папки assets.I дал File file = new File ("/ sdcard/sample.pdf"); Uri uri = Uri.fromFile (файл); intent.setDataAndType (uri, "application/pdf"); но не найден путь к файлу – sarath
ya..i поместил мой файл в папку с файлами и написал File file = new File ("android.resource: //com.pdftest/assets/sample"); .. но его путь передачи не был найдено ... – sarath