在Android中查看PDF文件

DMC*_*DMC 5 pdf android

我正在开发一个应用程序,其中一个按钮在按下时显示PDF文件.

显示此PDF文件的最佳方式是什么?

我可以通过将其复制到SD卡并使用已安装在设备上的adobe通过意图启动它来查看它.

但是我不能假设每个设备都安装了adobe,那么我的替代选择是什么?

我能将它转换成图像并以这种方式显示吗?

Sam*_*rba 1

我怀疑你想自己进行 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;
}
Run Code Online (Sandbox Code Playgroud)

摘自此处的Android 开发人员博客。

如果他们没有处理 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)));
}
Run Code Online (Sandbox Code Playgroud)

取自stackoverflow 链接。