Ich habe den Google Play Store mit folgendem Code geöffnet
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);.
Es wird jedoch eine vollständige Aktionsansicht angezeigt, um die Option (Browser/Play Store) auszuwählen. Ich muss die Anwendung direkt im Play Store öffnen.
Sie können dies mit dem Präfix market://
tun.
_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)));
}
_
Wir verwenden hier einen _try/catch
_ -Block, da ein Exception
ausgegeben wird, wenn der Play Store nicht auf dem Zielgerät installiert ist.
NOTE: Jede App kann sich registrieren, um mit dem _market://details?id=<appId>
_ Uri umgehen zu können. Wenn Sie sich speziell an Google Play wenden möchten, aktivieren Sie das Kontrollkästchen Berťák antworte
Viele Antworten hier schlagen vor,Uri.parse("market://details?id=" + appPackageName))
zum Öffnen von Google Play zu verwenden, aber ich denke, es ist unzureichend tatsächlich:
Einige Anwendungen von Drittanbietern können ihre eigenen Intent-Filter mit "market://"
-Schema verwenden, sodass sie gelieferte Uri anstelle von Google Play verarbeiten können (ich habe diese Situation mit z. Die Frage lautet "So öffnen Sie den Google Play Store?". Ich gehe davon aus, dass Sie keine andere Anwendung öffnen möchten. Bitte beachten Sie auch, dass z. App-Bewertung ist nur in GP Store App usw. relevant.
Zum Öffnen von Google Play UND NUR Google Play verwende ich diese Methode:
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);
}
}
Der Punkt ist, dass, wenn weitere Anwendungen neben Google Play unsere Absicht öffnen, der Dialog zur Auswahl von Apps übersprungen wird und die GP-App direkt gestartet wird.
UPDATE: Manchmal scheint es, dass nur die GP-App geöffnet wird, ohne das Profil der App zu öffnen. Wie TrevorWiley in seinem Kommentar vorschlug, könnte Intent.FLAG_ACTIVITY_CLEAR_TOP
das Problem beheben. (Ich habe es selbst noch nicht getestet ...)
Siehe diese Antwort , um zu verstehen, was Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
tut.
Gehen Sie auf den offiziellen Link zum offiziellen Android-Entwickler. Schritt für Schritt finden Sie den Code für Ihr Anwendungspaket vom Play Store.
Offizieller Link zum Android-Entwickler
http://developer.Android.com/distribute/tools/promote/linking.html
Verknüpfen mit einer Anwendungsseite
Von einer Website: http://play.google.com/store/apps/details?id=<package_name>
Von einer Android-App aus: market://details?id=<package_name>
Verknüpfen mit einer Produktliste
Von einer Website: http://play.google.com/store/search?q=pub:<publisher_name>
Von einer Android-App aus: market://search?q=pub:<publisher_name>
Verknüpfen mit einem Suchergebnis
Von einer Website: http://play.google.com/store/search?q=<search_query>&c=apps
Von einer Android-App aus: market://search?q=<seach_query>&c=apps
versuche dies
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.Android"));
startActivity(intent);
Alle obigen Antworten öffnen Google Play in einer neuen Ansicht derselben App, wenn Sie Google Play (oder eine andere App) tatsächlich unabhängig voneinander öffnen möchten:
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);
Der wichtige Teil ist, dass Google Play oder jede andere App unabhängig voneinander geöffnet wird.
Das meiste von dem, was ich gesehen habe, basiert auf dem Ansatz der anderen Antworten und es war nicht das, was ich brauchte, hoffentlich hilft dies jemandem.
Grüße.
Sie können überprüfen, ob der Google Play Store installiert ist. Wenn dies der Fall ist, können Sie das "market: //" - Protokoll verwenden.
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);
markt nutzen: //
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));
Die Antwort von Eric ist korrekt und der Code von Berťák funktioniert auch. Ich denke, das kombiniert beides eleganter.
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)));
}
Mit setPackage
zwingen Sie das Gerät, den Play Store zu verwenden. Wenn kein Play Store installiert ist, wird die Exception
abgefangen.
Du kannst tun:
final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));
referenz hier erhalten:
Sie können auch den in der akzeptierten Antwort dieser Frage beschriebenen Ansatz ausprobieren: Kann nicht feststellen, ob Google Play Store auf einem Android-Gerät installiert ist oder nicht
Ready-to-Use-Lösung:
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)));
}
}
}
Basierend auf Erics Antwort.
Sehr spät in der Party Offizielle Dokumente sind hier. Und der beschriebene Code ist
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
"https://play.google.com/store/apps/details?id=com.example.Android"));
intent.setPackage("com.Android.vending");
startActivity(intent);
Übergeben Sie bei der Konfiguration dieser Absicht "com.Android.vending"
an Intent.setPackage()
, sodass Benutzer die Details Ihrer App in der Google Play Store-App anstelle eines Auswahlbereichs . Für KOTLIN sehen
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(
"https://play.google.com/store/apps/details?id=com.example.Android")
setPackage("com.Android.vending")
}
startActivity(intent)
Wenn Sie eine Sofort-App mit Google Play Instant veröffentlicht haben, können Sie die App wie folgt starten:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
.buildUpon()
.appendQueryParameter("id", "com.example.Android")
.appendQueryParameter("launch", "true");
// Optional parameters, such as referrer, are passed onto the launched
// instant app. You can retrieve these parameters using
// Activity.getIntent().getData().
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId");
intent.setData(uriBuilder.build());
intent.setPackage("com.Android.vending");
startActivity(intent);
Für KOTLIN
val uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
.buildUpon()
.appendQueryParameter("id", "com.example.Android")
.appendQueryParameter("launch", "true")
// Optional parameters, such as referrer, are passed onto the launched
// instant app. You can retrieve these parameters using Activity.intent.data.
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId")
val intent = Intent(Intent.ACTION_VIEW).apply {
data = uriBuilder.build()
setPackage("com.Android.vending")
}
startActivity(intent)
Da die offiziellen Dokumentehttps://
anstelle von market://
verwendet, werden die Antworten von Eric und M3-n50 mit der Wiederverwendung von Code kombiniert (wiederholen Sie sich nicht):
Intent intent = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
try {
startActivity(new Intent(intent)
.setPackage("com.Android.vending"));
} catch (Android.content.ActivityNotFoundException exception) {
startActivity(intent);
}
Es wird versucht, mit der GPlay-App zu öffnen, sofern diese vorhanden ist, und es wird auf die Standardeinstellung zurückgegriffen.
Wenn Sie den Google Play Store von Ihrer App aus öffnen möchten, verwenden Sie diesen Befehl direkt: market://details?gotohome=com.yourAppName
. Dadurch werden die Google Play Store-Seiten Ihrer App geöffnet.
Alle Apps eines bestimmten Herausgebers anzeigen
Suchen Sie nach Apps, die die Abfrage nach Titel oder Beschreibung verwenden
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)));
}
}
Kotlin:
Erweiterung:
fun Activity.openAppInGooglePlay(){
val appId = BuildConfig.APPLICATION_ID
try {
this.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
} catch (anfe: ActivityNotFoundException) {
this.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appId")
)
)
}}
Methode:
fun openAppInGooglePlay(activity:Activity){
val appId = BuildConfig.APPLICATION_ID
try {
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
} catch (anfe: ActivityNotFoundException) {
activity.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=$appId")
)
)
}
}
Hier ist der endgültige Code aus den Antworten, dass zuerst versucht wird, die App mithilfe des Google Play Store und insbesondere des Play Store zu öffnen. Wenn dies fehlschlägt, wird die Aktionsansicht mit der Webversion gestartet: @ 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);
}
}
Meine Kotlin-Erweiterungsfunktion für diesen Zweck
fun Context.canPerformIntent(intent: Intent): Boolean {
val mgr = this.packageManager
val list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
return list.size > 0
}
Und in deiner Tätigkeit
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))
Ich habe die Antworten Berťák und Stefano Munarini kombiniert, um eine Hybridlösung zu erstellen, die sowohl Diese App bewerten als auch Mehr App anzeigen Szenario behandelt.
/**
* 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);
}
}
Verwendungszweck
@OnClick(R.id.ll_more_apps) public void showMoreApps() { openPlayStore(true, "Hitesh Sahu"); }
@OnClick(R.id.ll_rate_this_app) public void openAppInPlayStore() { openPlayStore(false, ""); }
Mit diesem Link wird die App automatisch in market geöffnet: // wenn Sie Android verwenden und im Browser, wenn Sie sich auf dem PC befinden.
https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1
Eine Kotlin-Version mit Fallback und aktueller Syntax
fun openAppInPlayStore() {
val uri = Uri.parse("market://details?id=" + context.packageName)
val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri)
var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
flags = if (Build.VERSION.SDK_INT >= 21) {
flags or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
} else {
flags or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
goToMarketIntent.addFlags(flags)
try {
startActivity(context, goToMarketIntent, null)
} catch (e: ActivityNotFoundException) {
val intent = Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))
startActivity(context, intent, null)
}
}
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")))
}
}
Leute, vergiss nicht, dass du tatsächlich mehr davon bekommen könntest. Ich meine zum Beispiel UTM-Tracking. https://developers.google.com/analytics/devguides/collection/Android/v4/campaigns
public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free";
public static final String APP_STORE_URI =
"market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
public static final String APP_STORE_GENERIC_URI =
"https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
try {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse(String.format(Locale.US,
APP_STORE_URI,
MODULE_ICON_PACK_FREE,
getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
} catch (Android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse(String.format(Locale.US,
APP_STORE_GENERIC_URI,
MODULE_ICON_PACK_FREE,
getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}