我正在开发一个用于显示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