Poproś użytkownika o ocenę aplikacji na Androida wewnątrz aplikacji

[1]} w mojej aplikacji na Androida chcę w pewnym momencie poprosić Użytkownika o ocenę aplikacji w Android market.

Szukając podejścia, znalazłem jakiś kod na tej stronie . Ten kod wydaje się działać bardzo dobrze.

Ale niestety, ten kod wydaje się wywoływać Komunikat o błędzie" wymuszone Zamknięcie", gdy Android market nie jest zainstalowany na telefonie użytkownika. Czy jest jakiś sposób, aby sprawdzić, czy Android market jest zainstalowany, a jeśli nie, nie próbuj wykonać kodu?

The linia, która powoduje błąd, jest prawdopodobnie tą, ponieważ nie może parsować URI:

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

A przy okazji, czy są jakieś inne rzeczy, które można by poprawić w tym kodzie?

Edit:

Kilka lat później umieściłem cały kod w małym projekcie biblioteki: AppRater na Githubie

Author: caw, 2011-11-07

10 answers

Możesz zawsze wywołać getInstalledPackages() z klasy PackageManager i sprawdzić, czy klasa market jest zainstalowana. Możesz również użyć queryIntentActivities () , aby upewnić się, że intencja, którą konstruujesz, będzie mogła być obsługiwana przez coś, nawet jeśli nie jest to aplikacja rynkowa. Jest to prawdopodobnie najlepsza rzecz do zrobienia, ponieważ jest najbardziej elastyczna i wytrzymała.

 14
Author: Kurtis Nusbaum,
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
2011-11-06 23:42:04

Oto kod, którego potrzebujesz, (konglomerat odpowiedzi Kurta i wnioskowanej informacji, Plus link i Pytanie):

/* This code assumes you are inside an activity */
final Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
final Intent rateAppIntent = new Intent(Intent.ACTION_VIEW, uri);

if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() > 0)
{
    startActivity(rateAppIntent);
}
else
{
    /* handle your error case: the device has no way to handle market urls */
}
 36
Author: xbakesx,
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-06-13 13:49:53

Możesz również użyć RateMeMaybe: https://github.com/Kopfgeldjaeger/RateMeMaybe

Daje sporo opcji do skonfigurowania (minimum dni / uruchamia się do pierwszego monitu, minimum dni / uruchamia się do każdego następnego monitu, jeśli użytkownik wybierze "nie teraz", tytuł okna dialogowego, wiadomość itp.). Jest również łatwy w użyciu.

Przykładowe użycie z README:

RateMeMaybe rmm = new RateMeMaybe(this);
rmm.setPromptMinimums(10, 14, 10, 30);
rmm.setDialogMessage("You really seem to like this app, "
                +"since you have already used it %totalLaunchCount% times! "
                +"It would be great if you took a moment to rate it.");
rmm.setDialogTitle("Rate this app");
rmm.setPositiveBtn("Yeeha!");
rmm.run();
 9
Author: Kopfgeldjaeger,
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
2013-03-21 20:19:06

Najpierw musisz policzyć użyte czasy;

SharedPreferences preferences = getSharedPreferences("progress", MODE_PRIVATE);
int appUsedCount = preferences.getInt("appUsedCount",0);
appUsedCount++;
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("appUsedCount", appUsedCount);
editor.apply();

if (appUsedCount==10 || appUsedCount==50 || appUsedCount==100 || appUsedCount==200 || appUsedCount==300){
    AskForRating(appUsedCount);
} else {
    finish();
}

Than you can prompt like this;

private void AskForRating(int _appUsedCount){

    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Please Rate Us");
    alert.setIcon(R.drawable.book);
    alert.setMessage("Thanks for using the application. If you like YOUR APP NAME please rate us! Your feedback is important for us!");
    alert.setPositiveButton("Rate it",new Dialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int whichButton){
            String url = "https://play.google.com/store/apps/details?id=YOUR PACKAGE NAME";
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });
    alert.setNegativeButton("Not now", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    });
    alert.show();
}
 5
Author: DiRiNoiD,
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-04-24 11:34:36

Nie wszystkie urządzenia z Androidem korzystają z rynku aplikacji. Kindle i Nook mają swój własny rynek, więc potrzeba kodu, aby sprawdzić, czy rynek istnieje, jest dobra. Chociaż powinien istnieć sposób, aby wysłać ocenę do właściwego rynku, bez względu na to, który to jest. Coś, na co warto zwrócić uwagę.

 1
Author: Kapt Kaos,
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-08 06:20:14

Ten prosty kod osiągnie to, co chcesz, bez potrzeby korzystania z zewnętrznych bibliotek lub czegokolwiek wymyślnego. Po prostu umieść go na wydarzeniu OnCreate na swojej głównej działalności. Zmienna RunEvery określi, jak często pojawi się komunikat o stawce. W przykładzie jest ustawiony na 10.

// Count times app has been opened, display rating message after number of times  
// By Rafael Duval   
    try {

        // Get the app's shared preferences
        SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this);

        // Get the value for the run counter
        int counter = app_preferences.getInt("counter", 0);

        // Do every x times
        int RunEvery = 10;

        if(counter != 0  && counter % RunEvery == 0 )
        {
            //Toast.makeText(this, "This app has been started " + counter + " times.", Toast.LENGTH_SHORT).show();

           AlertDialog.Builder alert = new AlertDialog.Builder(
                     MyActivity.this);
                   alert.setTitle("Please rate");
                   alert.setIcon(R.drawable.ic_launcher); //app icon here
                   alert.setMessage("Thanks for using this free app. Please take a moment to rate it.");

                   alert.setPositiveButton("Cancel",
                     new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog,
                        int whichButton) {                            
                          //Do nothing
                      }   
                     });

                   alert.setNegativeButton("Rate it",
                     new DialogInterface.OnClickListener() {

                      public void onClick(DialogInterface dialog, int which) {   

                           final String appName = getApplicationContext().getPackageName();
                           try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                              Uri.parse("market://details?id="
                                + appName)));
                           } catch (android.content.ActivityNotFoundException anfe) {
                            startActivity(new Intent(
                              Intent.ACTION_VIEW,
                              Uri.parse("http://play.google.com/store/apps/details?id="
                                + appName)));
                           }   

                      }
                     });
                   alert.show();            
        }


        // Increment the counter
        SharedPreferences.Editor editor = app_preferences.edit();
        editor.putInt("counter", ++counter);
        editor.commit(); // Very important          

    } catch (Exception e) {
        //Do nothing, don't run but don't break
    }           
 1
Author: Yo Mismo,
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
2015-08-22 15:28:15

Jeśli aplikacja została pobrana przez Android Market, użytkownicy będą mieli zainstalowany Android Market w telefonie, więc naprawdę nie widzę tego jako problemu. To wydaje się bardzo dziwne...

Aby uruchomić Android Market na stronie aplikacji, możesz użyć poniższej opcji, która jest nieco bardziej zautomatyzowana:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);
 0
Author: Michell Bak,
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
2011-11-06 23:41:34

Kiedy używam " market: / / details?id=" + getApplicationContext().getPackageName () otwiera na mnie rynek mobogenie, więc wolę używać https://play.google.com/store/apps/details?id= " + getApplicationContext ().getPackageName ()

 0
Author: Jemshit Iskenderov,
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-07-19 08:01:42

Użyj tego kodu

Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
// To count with Play market backstack, After pressing back button, 
// to taken back to our application, we need to add following flags to intent. 
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
                Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
    startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
    startActivity(new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
 0
Author: Pankaj Talaviya,
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-21 04:45:00

Są teraz inne opcje. Oto porównanie, które może pomóc Ci wybrać, którego z nich użyć.

Https://polljoy.com/blog/irate-vs-appirater-open-source-rating-prompts-alternatives

Tutaj wpisz opis obrazka

 -2
Author: Kilogen9,
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
2015-03-17 11:17:39