2012-06-06 15 views
86

私の最新のアプリに私の他のアプリのリンクがあります。モバイル版のgoogle playストアのオープンリンクandroid

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

このコードは、Google Playストアのブラウザ版を開きます。

携帯電話から開こうとすると、ブラウザまたはGoogle Playを使用するかどうかを尋ねるメッセージが表示され、2番目を選択するとGoogle Playストアのモバイル版が開きます。

これはどうやってすぐに起こるのですか?私は私に尋ねるのではなく、携帯電話からGoogle Playのモバイル版を直接開こうとしているのを見ることを意味します。 、これは(例えば、エミュレータ)をインストール市場を持たない任意のデバイス上でクラッシュします

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

は覚えておいてください:

+1

は私が最後の段落に2番目は、私にとって本当だったことを望みます。 http://developer.android.com/distribute/googleplay/promote/linking.html#OpeningDetailsのhttpリンクを使用しても、ユーザーがアプリやブラウザを選択するように求めるメッセージは表示されません。それは常にブラウザを想定しています。残念ながら、私は 'market://'プロトコルを使うことはできません。誰もこの行動を見ている? – SilithCrowe

答えて

260

は、指定したmarketプロトコルを使用することをお勧めします。一貫性のためにそのContextまたはサブクラスからgetPackageName()を使用している間

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

ブラウザで次のURLを開くとGoogle 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

Android用Chromeでmarket://で始まるリンクを開くようにしてください。検索結果のみを実行し、Google Playストアは開かないことがわかります。ここでPandoraのパッケージ名が正しいとすると、100個の正しいパッケージ名を与えることができますが、問題は変わりません。 –

3

ユーザーは、Googleがそのように再生時に、アプリケーションのページを開くためのAndroid Intentsライブラリを使用することができます。

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

[リンクのみの回答](http://meta.stackoverflow.com/tags/link-only-answers/info)はお勧めできませんので、SO回答は解決策の検索の終点にする必要があります(時間の経過とともに古くなる傾向がある参照の途中降機)。リンクを参考にして、ここにスタンドアロンの概要を追加することを検討してください。 – 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

以下のコード5月にはモバイル版で痛みのGoogle Playの表示アプリケーションリンクのためにあなたを助けます。

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

あなたは、Googleはアプリがインストールされているストアを再生するかどうかを確認することができ、アプリケーションのリンクについては

場合、"market://"プロトコルを使用することができます。 Google Playでの

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); 
関連する問題