Solicitar al usuario que califique una aplicación de Android dentro de la Aplicación


En mi aplicación Android, quiero pedirle al usuario en algún momento que califique la aplicación en Android Market.

Después de haber buscado un enfoque, he encontrado algún código en este sitio web. Este código parece funcionar muy bien.

Pero desafortunadamente, este código parece generar un mensaje de error de "Cierre forzado" cuando Android Market no está instalado en el teléfono del usuario. ¿Hay alguna manera de comprobar si Android market está instalado y, si no, no intente ejecutar el código?

El la línea que genera el error es probablemente esta, ya que no puede analizar el URI:

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

Y, por cierto, ¿hay otras cosas que podrían mejorarse en ese código?

Editar:

Unos años más tarde, he puesto todo el código en un pequeño proyecto de biblioteca: AppRater on GitHub

Author: caw, 2011-11-07

10 answers

Siempre puedes llamar a getInstalledPackages() desde la clase PackageManager y comprobar que la clase market está instalada. También puedes usar queryIntentActivities () para asegurarte de que la Intent que construyas pueda ser manejada por algo, incluso si no es la aplicación de mercado. Esto es probablemente la mejor cosa a hacer realmente porque es el más flexible y robusto.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-06 23:42:04

Aquí está todo el código que necesita, (un conglomerado de la respuesta de Kurt y la información inferida, más el enlace y la pregunta):

/* 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-13 13:49:53

También puedes usar RateMeMaybe: https://github.com/Kopfgeldjaeger/RateMeMaybe

Le da bastantes opciones para configurar (mínimo de días/inicios hasta el primer aviso, mínimo de días/inicios hasta cada siguiente aviso si el usuario elige "no ahora", título del diálogo, mensaje, etc.). También es fácil de usar.

Ejemplo de uso de 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-21 20:19:06

Primero debe contar las veces que se usa la aplicación;

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

De lo que puedes preguntar así;

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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-24 11:34:36

No todos los dispositivos Android utilizan el mercado de aplicaciones. Kindle y Nook tienen su propio mercado, por lo que la necesidad de código para comprobar si existe o no el mercado es buena. Aunque debería haber una manera de enviar la calificación al mercado correcto, sin importar cuál sea. Algo que investigar.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-08 06:20:14

Este simple código logrará lo que desea, sin necesidad de bibliotecas externas ni nada sofisticado. Simplemente póngalo en el evento onCreate en su actividad principal. La variable RunEvery determinará la frecuencia con la que aparecerá el mensaje rate. En el ejemplo se establece en 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-22 15:28:15

Si la aplicación se descargó a través de Android Market, los usuarios tendrán Android Market instalado en el teléfono, así que realmente no veo esto como un problema. Parece muy raro...

Puedes usar lo siguiente para lanzar Android Market en la página de tu aplicación, es un poco más automatizado:

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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-06 23:41:34

Cuando uso " market: / / details?id = " + getApplicationContext ().getPackageName() abre mobogenie market en mí, así que prefiero usar 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-19 08:01:42

Utilice este código

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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-21 04:45:00

Ahora hay otras opciones. Aquí hay una comparación que puede ayudarlo a elegir cuál usar.

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

introduzca la descripción de la imagen aquí

 -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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-17 11:17:39