我正在开发一个应用程序,其中一个按钮在按下时会显示一个 PDF 文件。
显示此 PDF 文件的最佳方式是什么?
我可以通过将其复制到 SD 卡并使用设备上已安装的 adobe 通过 intent 启动它来查看它。
但是我不能假设每台设备都安装了 adobe,那么我的备选方案是什么?
我能否将其转换为图像并以这种方式显示?
最佳答案
我怀疑您想自己进行 pdf 转换。您可以检查是否有应用程序来处理这样的 Intent :
/**
* 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;
}
取自安卓开发者博客here .
如果他们没有处理 pdf 的应用程序,则显示一个对话框,提示将它们发送到 Play 商店。您可以像这样创建启动 Play 商店的 Intent :
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计算器链接。
关于android - 在 Android 中查看 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13588974/