Now I am working on an application. Through my app users can read pdf files and if pdf reader is not there then my app automatically will install it from the site. This is the code I used for reading pdf file.
File file = new File("/sdcard/sample.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0 && file.isFile()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
}
My doubts are:
Try a different browser. Certain conditions on your computer, such as security settings or browser cookies, can prevent the Acrobat Reader Installer from downloading. Often, the easiest way to resolve an unsuccessful download is to try the download again using a different browser.
Step 1: Proceed to Download Go to the download page of the official website of Adobe Reader Offline Installer and click 'Install now'. It will initialize the download process and then you will see a dialog box. You can choose to 'Save File' for further installation of the program.
Close any browser that is displaying a PDF. Go to the Adobe Acrobat Reader download page and click Download Acrobat Reader. Click Save to download the Reader installer. When the downloaded file appears at the bottom of the browser window, click the .exe file for Reader.
To find out if you have Adobe Acrobat Reader installed on your computer, follow these steps: Click the Start button on your taskbar (usually found in the bottom left of the computer screen). Select All Programs from the pop-up menu. Verify that there is a folder called Adobe Acrobat listed.
From your code some complication..
Use this code,
Intent intent;
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(file, "application/pdf");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// No application to view, ask to download one
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("No Application Found");
builder.setMessage("Download one from Android Market?");
builder.setPositiveButton("Yes, Please",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent marketIntent = new Intent(Intent.ACTION_VIEW);
marketIntent
.setData(Uri
.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
}
I think this may help you:
private void loadDocInReader(String doc) throws ActivityNotFoundException, Exception {
try {
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.parse(doc), "application/pdf");
startActivity(intent);
}
catch (ActivityNotFoundException activityNotFoundException) {
activityNotFoundException.printStackTrace();
throw activityNotFoundException;
}
catch (Exception otherException) {
otherException.printStackTrace();
throw otherException;
}
}
If the Adobe reader is not installed you can drag user to this url:
https://market.android.com/details?id=com.adobe.reader
This will open Adobe Reader in Android Market mobile App. If users want, they can install.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With