Jak otworzyć sklep Google Play bezpośrednio z mojej aplikacji na Androida?

Otworzyłem Sklep Google play używając kodu follwing

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

Ale pokazuje mi Pełny Widok akcji, aby wybrać opcję(przeglądarka / Sklep play). Muszę otworzyć aplikację bezpośrednio w playstore.

Author: Vadim Kotov, 2012-08-01

18 answers

Możesz to zrobić za pomocą market:// przedrostek .

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

Używamy tutaj bloku try/catch, ponieważ Exception zostanie wyrzucony, jeśli Sklep Play nie jest zainstalowany na urządzeniu docelowym.

Uwaga: każda aplikacja może zarejestrować się jako zdolny do obsługi market://details?id=<appId> Uri, jeśli chcesz konkretnie kierować Google Play sprawdzić Berťák odpowiedź

 1203
Author: Eric,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-23 11:08:40

Wiele odpowiedzi tutaj sugerują, aby użyć Uri.parse("market://details?id=" + appPackageName)) aby otworzyć Google Play, ale myślę, że to niewystarczające w rzeczywistości:

Niektóre aplikacje innych firm mogą używać własnych filtrów intentowych z "market://" zdefiniowanym schematem, dzięki czemu mogą przetwarzać dostarczone Uri zamiast Google Play (doświadczyłem takiej sytuacji np. z aplikacją SnapPea). Pytanie brzmi: "Jak otworzyć sklep Google Play?", więc zakładam, że nie chcesz otworzyć żadnej innej aplikacji. Należy również pamiętać, że np. ocena aplikacji jest istotna tylko w aplikacji GP Store itp...

Aby otworzyć Google Play i tylko Google Play używam tej metody:

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

Chodzi o to, że gdy więcej aplikacji obok Google Play może otworzyć naszą intencję, okno wyboru aplikacji jest pomijane, a aplikacja GP jest uruchamiana bezpośrednio.

Aktualizacja: Czasami wydaje się, że otwiera tylko aplikację GP, bez otwierania profilu aplikacji. Jak zasugerował TrevorWiley w swoim komentarzu, Intent.FLAG_ACTIVITY_CLEAR_TOP może rozwiązać problem. (Nie testowałem jeszcze nie...)

Zobacz tę odpowiedź {[27] } aby zrozumieć, co robi Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.

 129
Author: Berťák,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 10:31:37

Przejdź na Android Developer official link jako tutorial krok po kroku zobacz i pobierz kod dla pakietu aplikacji ze Sklepu play jeśli istnieje lub play Store aplikacje nie istnieją, a następnie otwórz aplikację z przeglądarki internetowej.

Android Developer official link

Http://developer.android.com/distribute/tools/promote/linking.html

Linkowanie do strony aplikacji

From a web site: http://play.google.com/store/apps/details?id=<package_name>

Z aplikacji na Androida: market://details?id=<package_name>

Linkowanie do listy produktów

Ze strony: http://play.google.com/store/search?q=pub:<publisher_name>

Z aplikacji na Androida: market://search?q=pub:<publisher_name>

Linkowanie do wyniku wyszukiwania

Ze strony: http://play.google.com/store/search?q=<search_query>&c=apps

Z aplikacji na Androida: market://search?q=<seach_query>&c=apps

 55
Author: Najib Puthawala,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-22 09:41:54

Spróbuj tego

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);
 20
Author: Youddh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-01 05:36:53

Wszystkie powyższe odpowiedzi otwierają Google Play w nowym widoku tej samej aplikacji, Jeśli chcesz otworzyć Google Play (lub inną aplikację) niezależnie:

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

Ważne jest to, że faktycznie otwiera google play lub inną aplikację niezależnie.

Większość tego, co widziałem, wykorzystuje podejście innych odpowiedzi i nie było to, czego potrzebowałem, mam nadzieję, że to komuś pomoże.

Pozdrawiam.
 18
Author: Jonathan Caballero,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-28 05:20:05

Możesz sprawdzić, czy aplikacja Google Play Store jest zainstalowana, a w takim przypadku możesz użyć protokołu "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);
 12
Author: Paolo Rovelli,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-10 10:18:08

Użyj rynku: / /

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));
 9
Author: Johannes Staehlin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-03 14:08:32

Chociaż odpowiedź Erica jest poprawna, a kod Berťáka również działa. Myślę, że to łączy oba bardziej elegancko.

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

Używając setPackage, zmuszasz urządzenie do korzystania ze Sklepu Play. Jeśli nie ma zainstalowanego Sklepu Play, zostanie przechwycony Exception.

 8
Author: M3-n50,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 16:05:53

Możesz zrobić:

final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));

Pobierz referencję tutaj :

Możesz również spróbować podejścia opisanego w zaakceptowanej odpowiedzi na to pytanie: nie można określić, czy Sklep Google play jest zainstalowany lub nie na urządzeniu z Androidem

 6
Author: almalkawi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:10:45

Gotowe do użycia rozwiązanie:

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

}
Na podstawie odpowiedzi Erica.
 4
Author: Alexandr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-11 20:11:22

Jeśli chcesz otworzyć sklep Google Play z aplikacji, a następnie użyć tego polecenia directty: market://details?gotohome=com.yourAppName, otworzy strony sklepu Google Play aplikacji.

Pokaż wszystkie aplikacje według konkretnego wydawcy

Wyszukaj aplikacje, które korzystając z zapytania na swoim tytuł lub opis

Numer referencyjny: https://tricklio.com/market-details-gotohome-1/

 1
Author: Tahmid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-05 18:48:00
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)));
        }
    }
 1
Author: Anonymous,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-05 05:10:53

My kotlin entension function for this purpose

fun Context.canPerformIntent(intent: Intent): Boolean {
        val mgr = this.packageManager
        val list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
        return list.size > 0
    }

I w Twojej aktywności

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))
 1
Author: Arpan ßløødy ßadßøy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-01 10:31:22

Oto ostateczny kod z powyższych odpowiedzi, że pierwsze próby otwarcia aplikacji za pomocą aplikacji Google play store, a konkretnie play store, jeśli się nie powiedzie, uruchomi widok akcji za pomocą wersji internetowej: Credits to @ 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);
        }
    }
 1
Author: MoGa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-16 20:14:14

Połączyłem zarówno Berťák I Stefano Munarini odpowiedź na stworzenie rozwiązania hybrydowego, które obsługuje zarówno Oceń tę aplikację i Pokaż więcej aplikacji scenariusz.

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

Użycie

  • Aby Otworzyć Profil Wydawcy
   @OnClick(R.id.ll_more_apps)
        public void showMoreApps() {
            openPlayStore(true, "Hitesh Sahu");
        }
    [18]}aby otworzyć stronę aplikacji w PlayStore [19]}
@OnClick(R.id.ll_rate_this_app)
public void openAppInPlayStore() {
    openPlayStore(false, "");
}
 0
Author: Hitesh Sahu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-17 06:13:37

Ten link otworzy aplikację automatycznie w market: / / jeśli jesteś na Androidzie i w przeglądarce, jeśli jesteś na komputerze.

https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1
 0
Author: Nikolay Shindarov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-10 07:47:43

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")))
    }
}
 0
Author: Khemraj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-21 13:10:53

Jeśli chcesz otworzyć Play Market dla aplikacji Wyszukiwania (na przykład "pdf"), użyj tego:

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)));
    }
}
 -1
Author: CoolMind,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-29 09:32:52