I'm having this problem where I'm trying to open a PDF file in my app, if there are no PDF viewers on the device it redirects to the Play Store to download Adobe Reader. However I already downloaded Adobe Reader, it still catches ActivityNotFoundException
.
Here's my code:
Uri uri = Uri.parse(pdfUrl);
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// No application to view, ask to download one
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Viewer");
builder.setMessage("Download PDF Viewer?");
builder.setPositiveButton(getString("Okay"),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent innerIntent = new Intent(
Intent.ACTION_VIEW);
innerIntent.setData(Uri
.parse("market://details?id=com.adobe.reader"));
startActivity(innerIntent);
}
});
builder.setNegativeButton("Cancel"), null);
builder.create().show();
}
I already have downloaded the Adobe reader, the next time I run the app it still prompts me the dialog to download a PDF Viewer. What's the reason behind this?
Try this Code: