我正在開發一個用於顯示PDF文件的android應用程序。我想在我的android應用程序中打開Adobe Acrobat以打開PDF文件。 所以請幫助我如何做到這一點。Android - 如何在Android應用程序中打開Adobe Acrobat
在此先感謝。
問候 preet_Android
我正在開發一個用於顯示PDF文件的android應用程序。我想在我的android應用程序中打開Adobe Acrobat以打開PDF文件。 所以請幫助我如何做到這一點。Android - 如何在Android應用程序中打開Adobe Acrobat
在此先感謝。
問候 preet_Android
首先你需要檢查是否有您的系統提供一個PDF閱讀器。 因此,您需要調用讀取文件的意圖
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("path-to-document"));
intent.setType("application/pdf");
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
startActivity(intent);
}
else
{
Toast.maketext("hi there is no pdf viewer in your system");
}
你可以在你的應用程序中打開PDF文件:
File pdfFile = new File("/sdcard/read.pdf");
if(pdfFile.exists()) {
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
startActivity(pdfIntent);
}
謝謝,但我已經做到了。在這種情況下,應用程序將在後臺運行,adobe acrobat在前臺打開。但我想在我的應用程序中打開PDF文件。 – 2012-07-25 09:07:26
您可以在應用程序中默認打開pdf文件。如果您想在活動中顯示,則需要在項目中添加pdf庫。 – AkashG 2012-07-25 09:16:49
謝謝@ AkashG。那麼你可以告訴我我要添加哪個pdf庫以及如何使用它。 – 2012-07-25 09:45:13
File file = new File(mRealPath);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try{
//If pdf reader app already installed it will cause and exception
startActivity(intent);
}catch(Exception e)
{
// IF NO PDF APPLICATION INSTALLED ASK USER TO DOWNLOAD
}
安裝Adobe Reader並打開您的PDF文件。 https://play.google.com/store/apps/details?id=com.adobe.reader&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5hZG9iZS5yZWFkZXIiXQ .. – 2012-07-25 09:01:24
謝謝,但我已經做到了。在這種情況下,應用程序將在後臺運行,adobe acrobat在前臺打開。但我想在我的應用程序中打開PDF文件。 – 2012-07-25 09:05:59