android: open a pdf from my app using the built in pdf viewer

前端 未结 9 1731
温柔的废话
温柔的废话 2020-11-29 04:46

This was my original question:

I want to be able to open a pdf file in my app using the android\'s built in pdf viewer app, but i dont know how to

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 05:25

                FileFinalpath = SdCardpath + "/" + Filepath + Filename;
                File file = new File(FileFinalpath);
                if (file.exists()) {
                    Uri filepath = Uri.fromFile(file);
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(filepath, "application/pdf");
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    
                    try {
                        startActivity(intent);
                    } catch (Exception e) {
                        alert.showAlertDialog(PDF_Activity.this, "File Not Started...","File Not Started From SdCard ", false);             
                        Log.e("error", "" + e);
                    }
    
                } else {
                    alert.showAlertDialog(PDF_Activity.this, "File Not Found...","File Not Found From SdCard ", false);             
    
                }
    

提交回复
热议问题