2012-11-27 59 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計算器鏈接服用。