Here I am going to explain how to open a PDF file in your Android application
public void viewPDF()
{
File file = new File(Environment.getExternalStorageDirectory()
+ "testimage.pdf");
if (file .exists())
{
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();
}
}
}
Happy Coding :)
public void viewPDF()
{
File file = new File(Environment.getExternalStorageDirectory()
+ "testimage.pdf");
if (file .exists())
{
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();
}
}
}
Happy Coding :)
in nogut and above this method is not working
ReplyDeleteThanks for taking the time to share this.
ReplyDelete