Comment ouvrir le Google Play Store directement à partir de mon application Android?
j'ai ouvert le google play store en utilisant le code suivant
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.
mais il me montre une vue D'Action complète pour sélectionner l'option (browser/Play store). J'ai besoin d'ouvrir l'application dans playstore directement.
18 réponses
vous pouvez le faire en utilisant le market://
préfixe .
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("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
nous utilisons ici un bloc try/catch
car un Exception
sera lancé si le Play Store n'est pas installé sur le périphérique cible.
NOTE : toute application peut s'enregistrer comme capable de gérer le market://details?id=<appId>
Uri, si vous voulez cibler spécifiquement Google Play cochez la Berťák réponse
beaucoup de réponses ici suggèrent d'utiliser Uri.parse("market://details?id=" + appPackageName))
pour ouvrir Google Play, mais je pense qu'il est insuffisant en fait:
certaines applications tierces peuvent utiliser leurs propres filtres d'intention avec "market://"
schéma défini , ainsi ils peuvent traiter Uri fourni au lieu de Google Play (j'ai connu cette situation avec E. G. SnapPea application). La question Est "Comment ouvrir le Google Play Store?", je suppose donc que vous ne voulez pas ouvrir d'autres applications. Veuillez également noter que, par exemple, la classification app n'est pertinente que dans l'application GP Store, etc...
pour ouvrir Google Play et seulement Google Play j'utilise cette méthode:
public static void openAppRating(Context context) {
// you can also use BuildConfig.APPLICATION_ID
String appId = context.getPackageName();
Intent rateIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + appId));
boolean marketFound = false;
// find all applications able to handle our rateIntent
final List<ResolveInfo> otherApps = context.getPackageManager()
.queryIntentActivities(rateIntent, 0);
for (ResolveInfo otherApp: otherApps) {
// look for Google Play application
if (otherApp.activityInfo.applicationInfo.packageName
.equals("com.android.vending")) {
ActivityInfo otherAppActivity = otherApp.activityInfo;
ComponentName componentName = new ComponentName(
otherAppActivity.applicationInfo.packageName,
otherAppActivity.name
);
// make sure it does NOT open in the stack of your activity
rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// task reparenting if needed
rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
// if the Google Play was already open in a search result
// this make sure it still go to the app page you requested
rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// this make sure only the Google Play app is allowed to
// intercept the intent
rateIntent.setComponent(componentName);
context.startActivity(rateIntent);
marketFound = true;
break;
}
}
// if GP not present on device, open web browser
if (!marketFound) {
Intent webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id="+appId));
context.startActivity(webIntent);
}
}
le point est que lorsque plus d'applications à côté de Google Play peut ouvrir notre intention, le dialogue app-chooser est sauté et l'application GP est lancé directement.
UPDATE:
Parfois, il semble qu'il ouvre l'application GP seulement, sans ouvrir le profil de l'application. Comme TrevorWiley l'a suggéré dans son commentaire, Intent.FLAG_ACTIVITY_CLEAR_TOP
pourrait résoudre le problème. (Je n'ai pas testé moi-même encore...)
Voir cette réponse pour comprendre ce qu'est Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
ne.
allez sur Android Developer lien officiel comme tutoriel étape par étape voir et obtenir le code pour votre paquet d'application de play store si existe ou Play store apps n'existe pas, puis ouvrir l'application à partir du navigateur web.
Android Developer lien officiel
http://developer.android.com/distribute/tools/promote/linking.html
lien vers une application Page
D'un site web: http://play.google.com/store/apps/details?id=<package_name>
D'une application Android: market://details?id=<package_name>
lien à une liste de produits
D'un site web: http://play.google.com/store/search?q=pub:<publisher_name>
D'une application Android: market://search?q=pub:<publisher_name>
lien vers un résultat de recherche
D'un site web: http://play.google.com/store/search?q=<search_query>&c=apps
D'une application Android: market://search?q=<seach_query>&c=apps
essayez cette
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
toutes les réponses ci-dessus ouvrez Google Play dans une nouvelle vue de la même application, si vous voulez réellement ouvrir Google Play (ou toute autre application) indépendamment:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
// package name and activity
ComponentName comp = new ComponentName("com.android.vending",
"com.google.android.finsky.activities.LaunchUrlHandlerActivity");
launchIntent.setComponent(comp);
// sample to open facebook app
launchIntent.setData(Uri.parse("market://details?id=com.facebook.katana"));
startActivity(launchIntent);
la partie importante est qu'ouvre réellement google play ou toute autre application indépendamment.
la plupart de ce que j'ai vu utilise l'approche des autres réponses et ce n'était pas ce dont j'avais besoin espérons que cela aide quelqu'un.
Cordialement.
vous pouvez vérifier si L'application Google Play Store est installée et, si tel est le cas, 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);
use marché: / /
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));
alors que la réponse D'Eric est correcte et le code de Berťák fonctionne aussi. Je pense que cela combine les deux plus élégamment.
try {
Intent appStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
appStoreIntent.setPackage("com.android.vending");
startActivity(appStoreIntent);
} catch (android.content.ActivityNotFoundException exception) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
en utilisant setPackage
, vous forcez l'appareil à utiliser le Play Store. S'il n'y a pas de magasin de jeu installé, le Exception
sera attrapé.
Vous pouvez le faire:
final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));
obtenir une Référence ici :
vous pouvez également essayer l'approche décrite dans la réponse acceptée de cette question: ne peut pas déterminer si Google play store est installé ou non sur L'appareil Android
solution prête à l'emploi:
public class GoogleServicesUtils {
public static void openAppInGooglePlay(Context context) {
final String appPackageName = context.getPackageName();
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException e) { // if there is no Google Play on device
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
}
basé sur la réponse D'Eric.
si vous voulez ouvrir Google Play store à partir de votre application , alors utilisez cette commande directement: market://details?gotohome=com.yourAppName
, il ouvrira les pages Google Play store de votre application.
- Web: http://play.google.com/store/apps/details?id=
- App: market: / / details?id=
afficher toutes les applications d'un éditeur spécifique
- site Web: http://play.google.com/store/search?q=pub :
- App: market: / / search?q = pub:
recherche d'applications qui utilisent la requête sur son titre ou sa description
- Web: http://play.google.com/store/search?q=
- App: market: / / search?q=
public void launchPlayStore(Context context, String packageName) {
Intent intent = null;
try {
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" + packageName));
context.startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
}
}
Mon kotlin entension, à cet effet,
fun Context.canPerformIntent(intent: Intent): Boolean {
val mgr = this.packageManager
val list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
return list.size > 0
}
et dans votre activité
val uri = if (canPerformIntent(Intent(Intent.ACTION_VIEW, Uri.parse("market://")))) {
Uri.parse("market://details?id=" + appPackageName)
} else {
Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)
}
startActivity(Intent(Intent.ACTION_VIEW, uri))
voici le code final des réponses ci-dessus que les premières tentatives d'ouvrir l'application en utilisant L'application Google Play store et en particulier play store, si elle échoue, il va commencer la vue action en utilisant la version web: Crédits à @Eric, @Jonathan Caballero
public void goToPlayStore() {
String playStoreMarketUrl = "market://details?id=";
String playStoreWebUrl = "https://play.google.com/store/apps/details?id=";
String packageName = getActivity().getPackageName();
try {
Intent intent = getActivity()
.getPackageManager()
.getLaunchIntentForPackage("com.android.vending");
if (intent != null) {
ComponentName androidComponent = new ComponentName("com.android.vending",
"com.google.android.finsky.activities.LaunchUrlHandlerActivity");
intent.setComponent(androidComponent);
intent.setData(Uri.parse(playStoreMarketUrl + packageName));
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName));
}
startActivity(intent);
} catch (ActivityNotFoundException e) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreWebUrl + packageName));
startActivity(intent);
}
}
j'ai combiné les deux Berťák et Stefano Munarini réponse à la création d'une solution hybride qui gère à la fois Taux d'Application et Afficher Plus d'Application scénario.
/**
* This method checks if GooglePlay is installed or not on the device and accordingly handle
* Intents to view for rate App or Publisher's Profile
*
* @param showPublisherProfile pass true if you want to open Publisher Page else pass false to open APp page
* @param publisherID pass Dev ID if you have passed PublisherProfile true
*/
public void openPlayStore(boolean showPublisherProfile, String publisherID) {
//Error Handling
if (publisherID == null || !publisherID.isEmpty()) {
publisherID = "";
//Log and continue
Log.w("openPlayStore Method", "publisherID is invalid");
}
Intent openPlayStoreIntent;
boolean isGooglePlayInstalled = false;
if (showPublisherProfile) {
//Open Publishers Profile on PlayStore
openPlayStoreIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://search?q=pub:" + publisherID));
} else {
//Open this App on PlayStore
openPlayStoreIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + getPackageName()));
}
// find all applications who can handle openPlayStoreIntent
final List<ResolveInfo> otherApps = getPackageManager()
.queryIntentActivities(openPlayStoreIntent, 0);
for (ResolveInfo otherApp : otherApps) {
// look for Google Play application
if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {
ActivityInfo otherAppActivity = otherApp.activityInfo;
ComponentName componentName = new ComponentName(
otherAppActivity.applicationInfo.packageName,
otherAppActivity.name
);
// make sure it does NOT open in the stack of your activity
openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// task reparenting if needed
openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
// if the Google Play was already open in a search result
// this make sure it still go to the app page you requested
openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// this make sure only the Google Play app is allowed to
// intercept the intent
openPlayStoreIntent.setComponent(componentName);
startActivity(openPlayStoreIntent);
isGooglePlayInstalled = true;
break;
}
}
// if Google Play is not Installed on the device, open web browser
if (!isGooglePlayInstalled) {
Intent webIntent;
if (showPublisherProfile) {
//Open Publishers Profile on web browser
webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/search?q=pub:" + getPackageName()));
} else {
//Open this App on web browser
webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
}
startActivity(webIntent);
}
}
Utilisation
- Pour Ouvrir Les Éditeurs Profil
@OnClick(R.id.ll_more_apps) public void showMoreApps() { openPlayStore(true, "Hitesh Sahu"); }
- Pour Ouvrir la Page de l'Application sur PlayStore
@OnClick(R.id.ll_rate_this_app) public void openAppInPlayStore() { openPlayStore(false, ""); }
ce lien ouvrira l'application automatiquement dans le marché:// si vous êtes sur Android et dans le navigateur si vous êtes sur PC.
https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1
Kotlin
fun openAppInPlayStore(appPackageName: String) {
try {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")))
} catch (exception: android.content.ActivityNotFoundException) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")))
}
}
si vous voulez ouvrir le marché du jeu pour la recherche d'applications( par exemple, "pdf"), Utilisez ceci:
private void openPlayMarket(String query) {
try {
// If Play Services are installed.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=" + query)));
} catch (ActivityNotFoundException e) {
// Open in a browser.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/search?q=" + query)));
}
}