我知道這種類型的問題已經在SO上回答了很多次。但我無法找到符合我要求的答案。如何在Android客戶端上觸發Adobe Reader安裝
我需要知道,如果是安裝在客戶端上的Adobe閱讀器爲Android。如果不觸發從應用程序中讀取器的安裝,然後查看PDF ...
我是那種在Android新手...用代碼表示讚賞流..
感謝ü..
我知道這種類型的問題已經在SO上回答了很多次。但我無法找到符合我要求的答案。如何在Android客戶端上觸發Adobe Reader安裝
我需要知道,如果是安裝在客戶端上的Adobe閱讀器爲Android。如果不觸發從應用程序中讀取器的安裝,然後查看PDF ...
我是那種在Android新手...用代碼表示讚賞流..
感謝ü..
嗨注:Kunal我已經寫了一些代碼,請你穿越驗證它,因爲我還沒有測試它
public static final String QUICK_OFFICE_URL = "https://market.android.com/search?q=quick+office&so=1&c=apps";
public static final String QUICK_OFFICE_TRIAL_PACKAGE = "com.qo.android.am3.trial";
public static final String QUICK_OFFICE_PACKAGE = "com.qo.android.am3";
public static final String ADOBE_READER_URL="https://market.android.com/search?q=adobe+reader&so=1&c=apps";
public static final String ADOBE_READER_PACKAGE="com.adobe.reader";
public static final String DOCUMENTS_TO_GO_PACKAGE = "com.dataviz.docstogo";
public static final String GOOGLE_DOCUMENT_PACKAGE ="com.google.android.apps.docs";
public static final String OPEN_OFFICE_PACKAGE = "at.tomtasche.reader";
public static final String BEAMREADER_PACKAGE = "com.slgmobile.beamreader";
public static final String PDFVIEWER_PACKAGE = "mobi.mgeek.pdfviewer";
public static final String ANDROID_PDF_VIEWER_PACKAGE = "net.sf.andpdf.pdfviewer";
public static final String EZ_READER = "udk.android.reader";
public static final String PDF_VIEWER = "com.dzepina.pdfviewer";
private void openFileForReading(File file, String extension) {
Log.v(TAG, " openFileForReading(File file, String extension)");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
if (extension.equalsIgnoreCase("pdf")) {
Log.v(TAG, " file extension is .pdf");
if (appInstalledOrNot(Common.ADOBE_READER_PACKAGE)
|| appInstalledOrNot(Common.BEAMREADER_PACKAGE)
|| appInstalledOrNot(Common.PDF_VIEWER)
|| appInstalledOrNot(Common.PDFVIEWER_PACKAGE)
|| appInstalledOrNot(Common.EZ_READER)) {
intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
} else {
showAlertDialog(Common.ADOBE_READER_URL, file);
}
} else if (extension.equalsIgnoreCase("doc")) {
Log.v(TAG, " file extension is .doc");
if (appInstalledOrNot(Common.QUICK_OFFICE_PACKAGE)
|| appInstalledOrNot(Common.DOCUMENTS_TO_GO_PACKAGE)
|| appInstalledOrNot(Common.GOOGLE_DOCUMENT_PACKAGE)
|| appInstalledOrNot(Common.OPEN_OFFICE_PACKAGE)) {
intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
} else {
showAlertDialog(Common.QUICK_OFFICE_URL, file);
}
} else if (extension.equalsIgnoreCase("docx")) {
Log.v(TAG, " file extension is .docx");
if (appInstalledOrNot(Common.QUICK_OFFICE_PACKAGE)
|| appInstalledOrNot(Common.DOCUMENTS_TO_GO_PACKAGE)
|| appInstalledOrNot(Common.GOOGLE_DOCUMENT_PACKAGE)
|| appInstalledOrNot(Common.OPEN_OFFICE_PACKAGE)) {
intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
} else {
showAlertDialog(Common.QUICK_OFFICE_URL, file);
}
} else {
intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
}
}
private void showAlertDialog(final String uri, final File file) {
AlertDialog.Builder dialog = new AlertDialog.Builder(
DocumentsActivity.this);
dialog.setTitle("No Application Found !!!");
dialog.setMessage("Install App From Market");
dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(uri));
startActivity(intent);
}
});
dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
dialog.cancel();
}
});
dialog.show();
}
private boolean appInstalledOrNot(String packageName) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
如果你想如果讀者沒有安裝你可以解僱這個意圖在您的活動鏈接到市場:
Intent marketIntent = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=com.adobe.reader"));
startActivity(marketIntent);
查看PDF是需要一些技巧:
Intent showPDFIntent = new Intent();
showPDFIntent.setPackage("com.adobe.reader");
showPDFIntent.setDataAndType(Uri.fromFile(myPDFFile), "application/pdf");
startActivity(showPDFIntent);
我希望這有助於。
最良好的祝願, 添
觀察部工作正常... – 2012-04-24 12:59:31
Shabbir嗨,儘管Tim先給出答案,但我接受你的答案,因爲它有代碼在裏面......謝謝... – 2012-04-24 13:00:40
嗨Shabbir,雖然你有代碼,但有一個編譯錯誤...什麼是「Common」? – 2012-04-24 13:23:01
只是刪除共同。無論它出現在哪裏。它的常識你應該看到靜態字符串常量之上,並感謝您扣除我的觀點。 – 2012-04-24 13:25:02