我正在尝试从我的原始文件夹中传递 sdcard 一个 pdf 以默认意图打开它。
当我打开它时,它对我说 pdf 已损坏。因为我不太了解流的工作原理,所以我认为问题来自那里。
final String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
final String festivalDirectory_path = extStorageDirectory
+ Constants.PDF_STORAGE_PATH;
File pdfOutputFile = new File(festivalDirectory_path, "/");
if (pdfOutputFile.exists() == false) {
pdfOutputFile.mkdirs();
}
File pdfFile = new File(pdfOutputFile, nameOfThePdf);
try {
InputStream in = getResources().openRawResource(R.raw.blablublo);
FileOutputStream out = new FileOutputStream(pdfFile);
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = in.read(buffer)) > 0) {
out.write(buffer, 0, bufferLength);
}
out.close();
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
Uri path = Uri.fromFile(pdfFile);
// Uri path = Uri.parse(Constants.SPLASH_URI + R.raw.cartecannotpdf);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
希望有人能帮助我!
谢谢
雷诺