web-dev-qa-db-fra.com

lien ouvert de Google Play Store en version mobile Android

J'ai le lien de mes autres applications dans ma dernière application, et je les ouvre de cette façon.

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

ces codes ouvre la version du navigateur de Google Play Store.

Lors de la tentative d'ouverture depuis mon téléphone, celui-ci me demande si je souhaite utiliser un navigateur ou google play et si je choisis le second, il ouvre la version mobile de google Play Store.

Pouvez-vous me dire comment cela peut-il arriver à la fois? Je veux dire, ne me demandez pas mais ouvrez directement la version mobile de Google Play, celle que je vois tout en l'ouvrant directement depuis le téléphone.

88
ghostrider

Vous voudrez utiliser le protocole market spécifié:

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

N'oubliez pas que cela plantera tout appareil sur lequel Market n'est pas installé (l'émulateur, par exemple). Par conséquent, je suggérerais quelque chose comme:

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

Lorsque vous utilisez getPackageName() from Context ou une sous-classe de celui-ci pour des raisons de cohérence (merci @cprcrack !). Vous pouvez trouver plus d'informations sur Market Intents ici: link.

264
Eric

Le code ci-dessous peut vous aider à afficher le lien à une application de Google Play Sore en version mobile.

Pour le lien d'application: 

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

Pour le lien développeur: 

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();

            } 
6
Chirag Ghori

Vous pouvez utiliser Android Intents library pour ouvrir la page de votre application sur Google Play de la manière suivante:

Intent intent = IntentUtils.openPlayStore(getApplicationContext());
startActivity(intent);
3
Dmitriy Tarasov

Vous pouvez vérifier si Google Play Store app est installé et, le cas échéant, vous pouvez utiliser le protocole "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);
1
Paolo Rovelli
1
Denis Gladkiy

Ouvrez la page de l'application sur Google Play:

Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(intent);
0
user3150090