Display PDF file inside my android application

后端 未结 8 1664
日久生厌
日久生厌 2020-12-01 05:05

I cannot figure out how to show a PDF file inside an Android application. So far I\'ve found out that it is possible to launch an Intent and open the PDF using

8条回答
  •  忘掉有多难
    2020-12-01 05:14

    Uri path = Uri.fromFile(file );
    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(EmptyBlindDocumentShow.this,
                "No Application available to viewPDF",
                Toast.LENGTH_SHORT).show();
        }  
    }  
    

提交回复
热议问题