我正在开发一款应用程序,其中一个按钮在按下时会显示一个PDF文件。
最佳的显示PDF文件的方式是什么?
我可以通过将其复制到SD卡并使用已经安装在设备上的Adobe通过意图来查看它。
然而,我不能假设每个设备都安装了Adobe,那么我的替代选择是什么?
我能否将其转换为图像并以此方式显示它?
我觉得你不想自己进行PDF转换。你可以检查是否有应用程序来处理这样的意图:
/**
* Indicates whether the specified action can be used as an intent. This
* method queries the package manager for installed packages that can
* respond to an intent with the specified action. If no suitable package is
* found, this method returns false.
*
* @param context The application's environment.
* @param action The Intent action to check for availability.
*
* @return True if an Intent with the specified action can be sent and
* responded to, false otherwise.
*/
public static boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
如果他们没有处理PDF的应用程序,则显示一个对话框,提供将其发送到Play商店的选项。您可以创建意图来启动Play商店,如下所示:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details? id="+appName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
}
摘自this的stackoverflow链接。