When you want to customize the mime-type of the requested intent, the setter for reason resets the previously set Data parameter. Cute right?
And to overcome this great issue, the API has another method setDataAndType(). See what they did there?
Anyways - here's a correct method (opening a PDF in this example):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File sd = new File(Environment.getExternalStorageDirectory() + File.separator + PDFFolder + File.separator + model.get(idx)); | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(sd)); | |
intent.setDataAndType(Uri.fromFile(sd), "application/pdf"); | |
try { | |
getContext().startActivity(intent); | |
}catch(ActivityNotFoundException e){ | |
//Show a message that PDF viewer is not installed | |
} |