我正在使用此代码在下载文件夹中打开PDF文件
public void open_pdf(View view) {
String fileName ="2019_10_22_03_37_25_pm5906.pdf";
File pdfFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()
+ File.separator + fileName);
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.actION_VIEW);
pdfIntent.setDataAndType(path,"application/pdf");
pdfIntent.setflags(Intent.flaG_actIVITY_CLEAR_TOP);
Toast.makeText(this,"hello: "+pdfFile,Toast.LENGTH_SHORT).show();
t1 = findViewById(R.id.textView);
t1.setText(path.toString() + "####"+pdfFile.getPath());
try{
startactivity(pdfIntent);
}catch(activityNotFoundException e){
Toast.makeText(this,"No Application available to view PDF",Toast.LENGTH_SHORT).show();
t1.setText("No applicatoin available");
} catch ( Exception e){
Toast.makeText(this,"No App found,sorry",Toast.LENGTH_SHORT).show();
} finally {
Toast.makeText(this,"This is finally block",Toast.LENGTH_SHORT).show();
}
}
有几个问题
-
PDF文件未打开,URI = file:///storage/emulated/0/Download/2019_10_pm.pdf似乎很合适
-
没有异常被调用,也没有错误。
可能是什么问题?我是Android编程的新手