원시 목적의 폴더에서 sdcard를 pdf로 전달하여 기본 의도로 열려고합니다.애셋에서 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);
누군가 나를 도울 수 있기를 바랍니다. 솔루션 절반 완료처럼
들으
르노
파일을 _copying_하고 있지 않습니다. http://stackoverflow.com/a/4530294/1321873 – Rajesh
thx에서이 링크를보고 결과에서 내 코드를 수정했지만 다른 것을 놓치지 마세요 –
지금은 어떤 문제가 있습니까? 문제를 격리 시키십시오. 복사 한 파일을 읽을 수 있는지 확인하십시오 (예 : 컴퓨터로 다운로드). – Rajesh