20

I am currently developing an application in Android Where I want to give some functionality to user to rate the current application. Their will be a button on it's click it will ask ask whether user want to rate the application or not? If yes will will go to market application on device to rate application (Market should show this application.) or it will open browser which will load market & showing this application. Any one used this kind of functionality before. Please provide some help.

Thank You.

Sandip Jadhav
  • 7,377
  • 8
  • 44
  • 76
  • 3
    Does this answer your question? ["Rate This App"-link in Google Play store app on the phone](https://stackoverflow.com/questions/10816757/rate-this-app-link-in-google-play-store-app-on-the-phone) – Yoav Feuerstein May 25 '20 at 14:18

4 Answers4

47

I always use a method like this one:

private void launchMarket() {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.couldnt_launch_market, Toast.LENGTH_LONG).show();
    }
}
Cristian
  • 198,401
  • 62
  • 356
  • 264
  • 1
    @Cristian---Thanks for quick reply.. Just one query-- at the place of getPackageName() I should provide my application package right? Also I think I need to detect device has market application or not? In general device must have it but in case if user removed it So how to check market app is present or not? – Sandip Jadhav Aug 01 '11 at 14:37
  • 1
    http://developer.android.com/reference/android/content/Context.html#getPackageName%28%29 No, it'll grab the package name for you. This throws an exception if no market app is installed, and displays a toast. – Rob Aug 01 '11 at 15:00
  • cant it download market app if it is deleted by user .......is there any possibility? @Cristian – Erum Feb 07 '14 at 19:25
  • I think it's not possible. Also... only advanced users will delete the market app, if they don't want to have it let it be. – Cristian Feb 07 '14 at 20:59
3
public class AppRater {
private final static String APP_TITLE = "App Name";// App Name
private final static String APP_PNAME = "com.example.name";// Package Name

private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches

public static void app_launched(Context mContext) {
    SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
    if (prefs.getBoolean("dontshowagain", false)) { return ; }

    SharedPreferences.Editor editor = prefs.edit();

    // Increment launch counter
    long launch_count = prefs.getLong("launch_count", 0) + 1;
    editor.putLong("launch_count", launch_count);

    // Get date of first launch
    Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
    if (date_firstLaunch == 0) {
        date_firstLaunch = System.currentTimeMillis();
        editor.putLong("date_firstlaunch", date_firstLaunch);
    }

    // Wait at least n days before opening
    if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
        if (System.currentTimeMillis() >= date_firstLaunch + 
                (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
            showRateDialog(mContext, editor);
        }
    }

    editor.commit();
}   

public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
    final Dialog dialog = new Dialog(mContext);
    dialog.setTitle("Rate " + APP_TITLE);

    LinearLayout ll = new LinearLayout(mContext);
    ll.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(mContext);
    tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
    tv.setWidth(240);
    tv.setPadding(4, 0, 4, 10);
    ll.addView(tv);

    Button b1 = new Button(mContext);
    b1.setText("Rate " + APP_TITLE);
    b1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
            dialog.dismiss();
        }
    });        
    ll.addView(b1);

    Button b2 = new Button(mContext);
    b2.setText("Remind me later");
    b2.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    ll.addView(b2);

    Button b3 = new Button(mContext);
    b3.setText("No, thanks");
    b3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (editor != null) {
                editor.putBoolean("dontshowagain", true);
                editor.commit();
            }
            dialog.dismiss();
        }
    });
    ll.addView(b3);

    dialog.setContentView(ll);        
    dialog.show();        
}}

Now Integrate class to your activity like this ->

AppRater.app_launched(this);
Karan Datwani
  • 532
  • 6
  • 6
1

Here is simple solution for :

final String appPackageName = "com.name.app";

private void launchMyMarket() {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        startActivity(myAppLinkToMarket);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, " unable to find source market app! try again", Toast.LENGTH_LONG).show();
    }
}
Dolly Rosy
  • 140
  • 10
1

The answers here won't take you directly to playstore if you have multiple market apps on your phone. Instead it will show a picker dialog.

To open playstore directly, use this:

private fun rateUs() {
    val uri = Uri.parse("https://play.google.com/store/apps/details?id=" + activity?.packageName.toString() + "")
    val intent = Intent(Intent.ACTION_VIEW, uri)
    startActivity(intent)
}
Adekola Akano
  • 169
  • 2
  • 7