응용 프로그램 (내부 저장소)에 PDF 파일을 열려고합니다. 다음 adobe pdf가 열리면 다음 코드가 나타납니다. 문서 경로가 잘못되었습니다. "앱 내부에서 PDF 파일을 읽을 수만 있습니까? 주시기 바랍니다없는 경우 나 I 앱의 내부 저장 디렉토리에 미리응용 프로그램 내부에서 샘플 PDF 파일을 만들고 열고 엽니 다.
File file_source = new File(getApplicationContext().getFilesDir()+"/"+"sample.pdf");
String string = "Hello world!";
try
{
file_source.createNewFile();
FileOutputStream outputStream;
outputStream = openFileOutput("sample.pdf", Context.MODE_PRIVATE);
outputStream.write(string.getBytes());
outputStream.close();
if(file_source.exists())
{
Uri path = Uri.fromFile(file_source);
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setDataAndType(path, "application/pdf");
intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent1);
}
catch (ActivityNotFoundException e) {
Toast.makeText(this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
Intent intent2 = new Intent(Intent.ACTION_VIEW);
startActivity(intent2);
}
}
else
{
Log.d("TAG","no file exists");
}
}
catch (FileNotFoundException e) {
Log.d("TAG","File not found");
}
catch (IOException ioe) {
Log.d("TAG","Exception while reading file" + ioe);
}
안녕하세요 내가 pdf 파일은 항상 "문서가 비어"라고하는 following.But했다 .There는 출력 파일 extension.please이 무엇인지 외부 storage.Please 도움 – user3706655
내부에서 복사 뭔가 잘못이다 .pdf가 없는지 확인한 다음 'Outputpdf'를 'Outputpdf.pdf'로 변경하십시오. –
안녕하세요 Chandra 덕분에 pdf 파일을 열 수 있습니다. 문제점은 Environment.getExternalStorageDirectory가되어야하는 잘못된 "outputpdf"경로를 제공하고있었습니다. .... – user3706655