2012-11-27 56 views
5

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

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

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

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

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

+0

我会建议与意图一致,如果没有有效的PDF阅读器应用程序显示一个对话框,将用户到市场安装一个。 – FoamyGuy

回答

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; 
} 

从Android开发者博客采取here

如果他们没有处理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计算器链接服用。