pdf 파일을 내부 저장소로 다운로드 한 다음 작업보기로 가져 오는 단추를 프로그래밍 방식으로 만듭니다. pdf 뷰어에 파일이 존재하지 않거나 파일을 볼 수 없다고 말하면 파일 []과 토스트를 list 할 수 있습니다.내부 저장소에 pdf 파일을 다운로드하고 있지만 pdf 뷰어에서 찾을 수 없습니다.
다운로드 중에 내부 저장소에 쓰기의 주요 구성 요소입니다.
private File file;
file = new File(mContext.getFilesDir(), filename+".pdf");
// Output stream to write file in internal storage
OutputStream output = new BufferedOutputStream(new FileOutputStream(file));
그런 다음 다른 활동에 나는 데이터베이스에서 파일 이름을 얻을 버튼
// ....Inside a for loop .....
Button c3 = new Button(this);
c3.setText("view");
c3.setId(p.getPosterID());
c3.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
File pdfFile = getBaseContext().getFileStreamPath(filename+".pdf");
if (pdfFile.exists()){
Uri path = Uri.fromFile(pdfFile);
//================================================================================
Log.d("path: ", path.toString());
//this will log: file:///data/data/com.myapp.posterviewer/files/5453b54b83b5f.pdf
//================================================================================
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e){
Toast.makeText(ListPosters.this, "No Application Available", Toast.LENGTH_LONG).show();
}
}
else{
Toast.makeText(ListPosters.this, "The file does not exist", Toast.LENGTH_LONG).show();
}
}
});
내가 바로 열린 우리당 경로와 경로를 생성하는 건가요있는 테이블을 만들? 앱 폴더에있을 때 Windows 탐색기에서 파일을 볼 수 없습니다. 하지만 내 모든 검사 파일이 존재하고 그것이 응용 프로그램 루트 폴더에있을 거라 생각했다.
권한 문제 일 수 있습니다. PDF 뷰어에서 앱의 내부 폴더를 읽을 수 있는지 확실하지 않습니다. 브라우저에서 무언가를 다운로드 할 때도 사용되는 외부 다운로드 폴더를 사용해보십시오. – cYrixmorten
또는 FileProvider를 사용하여 내부 저장소의 파일을 제공하십시오. – CommonsWare
@CommonsWare .. 나는 방금 PDF보기 라이브러리를 사용하는 것에 대해 읽었으며 누군가가 2012 년 게시물에서 나를 언급했습니다. 따라서 2 년 후에 어떤 PDF보기 라이브러리를 권하겠습니까? 나는 java/android에서 시작하기 때문에 FileProvider는 나에게 새로운 것이다. – silversunhunter