Opening pdf file programmatically is going into menu page?

前端 未结 2 661
野趣味
野趣味 2021-01-07 13:40

How come every time i try to open a pdf file in my SDCARD using the following code, it doesn\'t actually open the pdf file itself, but goes into the menu of adobe reader? Is

2条回答
  •  一整个雨季
    2021-01-07 14:27

    Here I am giving my pdf file name. You give your file name.

        private static String FILE = Environment.getExternalStorageDirectory().getPath()+"/TestPDF.pdf";   
    
        File file = new File(FILE);
    
        if (file.exists()) {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    
            try {
                startActivity(intent);
            } 
            catch (ActivityNotFoundException e) {
                Toast.makeText(this, 
                    "No Application Available to View PDF", 
                    Toast.LENGTH_SHORT).show();
            }
        }
    

提交回复
热议问题