2012-06-06 92 views
86

我有我的其他應用程序在我的最新應用程序的鏈接,我打開它們的方式。谷歌Play商店在手機版的開放鏈接android

Uri uri = Uri.parse("url"); 
Intent intent = new Intent (Intent.ACTION_VIEW, uri); 
startActivity(intent); 

此代碼打開google play store的瀏覽器版本。

當試圖從我的手機打開時,手機會提示是否要使用瀏覽器或谷歌播放,如果我選擇第二個,它會打開手機版Google Play商店。

你能告訴我這是怎麼發生的嗎?我的意思是不要問我,而是直接打開谷歌手機版,這是我從手機直接打開時看到的版本。

+1

我希望爲我的第二到最後一段是真實的。使用此處找到的http鏈接:http://developer.android.com/distribute/googleplay/promote/linking.html#OpeningDetails不會提示用戶選擇應用程序或瀏覽器。它總是假定瀏覽器。不幸的是,我也不能使用'market://'協議。其他人看到這種行爲? – SilithCrowe

回答

260

你要使用指定的market協議:

final String appPackageName = "com.example"; // Can also use getPackageName(), as below 
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); 

請記住,這會崩潰,它沒有安裝任何市場的設備上(模擬器,例如)。在使用getPackageName()Context或子類及其一致性

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object 
try { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); 
} catch (android.content.ActivityNotFoundException anfe) { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName))); 
} 

:因此,我建議像(感謝@cprcrack!)。你可以在這裏找到更多關於市場意圖的信息:link

+0

在瀏覽器中打開以下內容不會打開Goog​​le Play:market:// details?id = pandora –

+1

ID是包名稱,而不是應用程序名稱。試試'market:// details?id = com.PandoraTV'(假設[this](https://play.google.com/store/apps/details?id=com.PandoraTV)是你想要的應用程序)。 – Eric

+0

嘗試打開任何以market://在Chrome for Android開頭的鏈接。您會看到它僅執行搜索結果,但不會打開Goog​​le Play商店。如果潘多拉軟件包的名稱在這裏是正確的,我可以給你一百個正確的軟件包名稱,這不會改變這個問題。 –

3

可以使用Android Intents庫在谷歌播放像打開您的應用程序頁面:

Intent intent = IntentUtils.openPlayStore(getApplicationContext()); 
startActivity(intent); 
+2

請注意,[只有鏈接的答案](http://meta.stackoverflow.com/tags/link-only-answers/info)不鼓勵,所以答案應該是搜索解決方案的終點(vs.而另一個引用的中途停留時間往往會隨着時間推移而過時)。請考慮在此添加獨立的摘要,並將鏈接保留爲參考。 – kleopatra

+4

這將是有益的,包括一個聲明,這是你的圖書館和[功能實現](http://grepcode.com/file/repo1.maven.org/maven2/com.dmitriy-tarasov/android-intents/ 1.1.0/com/dmitriy/tarasov/android/intents/IntentUtils.java#IntentUtils.openPlayStore%28com.dmitriy.tarasov.android.intents.Context%29)與接受的答案几乎相同。 –

5

下面的代碼可能有助於爲谷歌的顯示應用鏈接移動版打痛。

對於應用程序鏈接:

Uri uri = Uri.parse("market://details?id=" + mContext.getPackageName()); 
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri); 

    try { 
     startActivity(myAppLinkToMarket); 

     } catch (ActivityNotFoundException e) { 

     //the device hasn't installed Google Play 
     Toast.makeText(Setting.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show(); 
       } 

對於開發者聯繫:

Uri uri = Uri.parse("market://search?q=pub:" + YourDeveloperName); 
Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri); 

      try { 

       startActivity(myAppLinkToMarket); 

      } catch (ActivityNotFoundException e) { 

       //the device hasn't installed Google Play 
       Toast.makeText(Settings.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show(); 

      } 
1

您可以檢查谷歌Play商店安裝應用程序,如果是這樣的的情況下,您可以使用「market://」協議。在谷歌播放

final String my_package_name = "........." // <- HERE YOUR PACKAGE NAME!! 
String url = ""; 

try { 
    //Check whether Google Play store is installed or not: 
    this.getPackageManager().getPackageInfo("com.android.vending", 0); 

    url = "market://details?id=" + my_package_name; 
} catch (final Exception e) { 
    url = "https://play.google.com/store/apps/details?id=" + my_package_name; 
} 


//Open the app page in Google Play store: 
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 
startActivity(intent); 
0

打開應用頁面:

Intent intent = new Intent(Intent.ACTION_VIEW, 
       Uri.parse("market://details?id=" + context.getPackageName())); 
startActivity(intent); 
相關問題