Montaser_m

Prompt engaged users to rate your app in the Android market

Feb 18th, 2020
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. Hello evre one enjoy at this cod 🤩
  2. https://bit.ly/2SCOD3A
  3. public class AppRater{
  4. private final static String APP_TITLE = "YOUR-APP-NAME";
  5. private final static String APP_PNAME = "YOUR-PACKAGE-NAME";
  6.  
  7. private final static int DAYS_UNTIL_PROMPT = 3;
  8. private final static int LAUNCHES_UNTIL_PROMPT = 7;
  9.  
  10. public static void app_launched(Context mContext) {
  11. SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
  12. if (prefs.getBoolean("dontshowagain", false)) { return ; }
  13.  
  14. SharedPreferences.Editor editor = prefs.edit();
  15.  
  16. // Increment launch counter
  17. long launch_count = prefs.getLong("launch_count", 0) + 1;
  18. editor.putLong("launch_count", launch_count);
  19.  
  20. // Get date of first launch
  21. Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
  22. if (date_firstLaunch == 0) {
  23. date_firstLaunch = System.currentTimeMillis();
  24. editor.putLong("date_firstlaunch", date_firstLaunch);
  25. }
  26.  
  27. // Wait at least n days before opening
  28. if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
  29. if (System.currentTimeMillis() >= date_firstLaunch +
  30. (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
  31. showRateDialog(mContext, editor);
  32. }
  33. }
  34.  
  35. editor.commit();
  36. }
  37.  
  38. public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
  39. final Dialog dialog = new Dialog(mContext);
  40. dialog.setTitle("Rate " + APP_TITLE);
  41.  
  42. LinearLayout ll = new LinearLayout(mContext);
  43. ll.setOrientation(LinearLayout.VERTICAL);
  44.  
  45. TextView tv = new TextView(mContext);
  46. tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
  47. tv.setWidth(240);
  48. tv.setPadding(4, 0, 4, 10);
  49. ll.addView(tv);
  50.  
  51. Button b1 = new Button(mContext);
  52. b1.setText("Rate " + APP_TITLE);
  53. b1.setOnClickListener(new OnClickListener() {
  54. public void onClick(View v) {
  55. mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
  56. dialog.dismiss();
  57. }
  58. });
  59. ll.addView(b1);
  60.  
  61. Button b2 = new Button(mContext);
  62. b2.setText("Remind me later");
  63. b2.setOnClickListener(new OnClickListener() {
  64. public void onClick(View v) {
  65. dialog.dismiss();
  66. }
  67. });
  68. ll.addView(b2);
  69.  
  70. Button b3 = new Button(mContext);
  71. b3.setText("No, thanks");
  72. b3.setOnClickListener(new OnClickListener() {
  73. public void onClick(View v) {
  74. if (editor != null) {
  75. editor.putBoolean("dontshowagain", true);
  76. editor.commit();
  77. }
  78. dialog.dismiss();
  79. }
  80. });
  81. ll.addView(b3);
  82.  
  83. dialog.setContentView(ll);
  84. dialog.show();
  85. }
  86. }
Add Comment
Please, Sign In to add comment