Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 2.69 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. app rater not working correctly for me
  2. public class AppRater {
  3. private final static String APP_TITLE = "name";
  4. private final static String APP_PNAME = "com.code.code";
  5.  
  6. private final static int DAYS_UNTIL_PROMPT = 1;
  7. private final static int LAUNCHES_UNTIL_PROMPT = 1;
  8.  
  9. public static void app_launched(Context mContext) {
  10.     SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
  11.     if (prefs.getBoolean("dontshowagain", false)) { return ; }
  12.  
  13.     SharedPreferences.Editor editor = prefs.edit();
  14.  
  15.     // Increment launch counter
  16.     long launch_count = prefs.getLong("launch_count", 0) + 1;
  17.     editor.putLong("launch_count", launch_count);
  18.  
  19.     // Get date of first launch
  20.     Long date_firstLaunch = prefs.getLong("date_firstlaunch", 1);
  21.     if (date_firstLaunch == 1) {
  22.         date_firstLaunch = System.currentTimeMillis();
  23.         editor.putLong("date_firstlaunch", date_firstLaunch);
  24.     }
  25.  
  26.  // Wait at least n days before opening
  27.     if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
  28.         if (System.currentTimeMillis() >= date_firstLaunch +
  29.                 (DAYS_UNTIL_PROMPT * 0 * 24 * 60 * 1000)) {
  30.             showRateDialog(mContext, editor);
  31.         }
  32.     }
  33.  
  34.     editor.commit();
  35. }  
  36.  
  37. public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
  38.     final Dialog dialog = new Dialog(mContext);
  39.     dialog.setTitle("Rate " + APP_TITLE);
  40.  
  41.     LinearLayout ll = new LinearLayout(mContext);
  42.     ll.setOrientation(LinearLayout.VERTICAL);
  43.  
  44.     TextView tv = new TextView(mContext);
  45.     tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!");
  46.     tv.setWidth(600);
  47.     tv.setPadding(24, 0, 24, 60);
  48.     ll.addView(tv);
  49.  
  50.     Button b1 = new Button(mContext);
  51.     b1.setText("Rate " + APP_TITLE);
  52.     b1.setOnClickListener(new OnClickListener() {
  53.         public void onClick(View v) {
  54.             mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
  55.             dialog.dismiss();
  56.         }
  57.     });      
  58.     ll.addView(b1);
  59.  
  60.     Button b2 = new Button(mContext);
  61.     b2.setText("Remind me later");
  62.     b2.setOnClickListener(new OnClickListener() {
  63.         public void onClick(View v) {
  64.             dialog.dismiss();
  65.  
  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. }