[Android] Android 學習筆記:開啟 Google Play app 至指定的 app

[Android] Android 學習筆記:開啟 Google Play app 至指定的 app

在先前 從 app 中執行外部的 app 這篇文章中,說明了如何去呼叫外部的 app,

但如果那個 app 不存在的話,可以怎麼做呢?

一種做法是直接把 Google Play app 叫起來,這樣使用者就可以直接安裝那個 app~

 

在 stackoverflow: open link of google play store in mobile version android 這篇文章中,

找到了相當不錯的方式,就是先試著開啟 Google Play app,

但如果沒有安裝的話,就導到網頁版的 Google Play~

 

舉例來說,假設我現在想要呼叫的是 Google+,

他的套件名稱是 com.google.android.apps.plus,因此我可以這麼做:

String sParam = “com.google.android.apps.plus”;

try
{
// Open app with Google Play app
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“market://details?id=”+sParam));
startActivity(intent);
}
catch (android.content.ActivityNotFoundException anfe)
{
// Open Google Play website
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“http://play.google.com/store/apps/details?id=”+sParam));
startActivity(intent);
}

 

(本頁面已被瀏覽過 992 次)

2 thoughts on “[Android] Android 學習筆記:開啟 Google Play app 至指定的 app

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料