1

there is a button in my main activity . by default its invisible but I wanna make it visible one day after installation of my app (or one day after first run of my app ). so when the user install my app he can't see my button . but one day after installation he can see my button. how can I do it?

jack peterson
  • 287
  • 1
  • 2
  • 14
  • http://stackoverflow.com/questions/2831333/how-to-get-app-install-time-from-android and then check if passed a day. (p.s you could cache this value somewhere to don't execute it everytime) – Marco Acierno Dec 13 '14 at 09:04

3 Answers3

3

Here is the solution... Firstly get the installation date then compare that date with current date. if its greater than 1 day you can show your button.

Here is the code...

// ****************** To know installation date of application for button show **************//
    try {
        appInstalledDate = Splash.this.getPackageManager().getPackageInfo("your package name", 0).firstInstallTime;
         SimpleDateFormat sdf = new SimpleDateFormat("dd MMM,yyyy HH:mm");
            Date resultdate = new Date(appInstalledDate);
        Log.v("Installation date of app is ",","+resultdate);
    } catch (Exception e) {
        e.printStackTrace();
    }

Here you can show your button

try {
                SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");

                Date resultdate = new Date(Long.parseLong(prefs.getString("email_prompt", "")));
                                    Log.v("current date ",","+sdf.format(new Date().getTime()));
                long diff = new Date().getTime() - resultdate
                long diffMinutes = (diff / 1000) / 60;
                long diffMinutes = (TimeUnit.MILLISECONDS.toMinutes(diff));
                Log.v("Difference in minutes is ",","+diffMinutes);

                if(1440 < diffMinutes)
                {
                 yourButton.show(); // show your button

                }
            } catch (Exception e) {
                e.printStackTrace();

            }
Ankit Sharma
  • 1,261
  • 2
  • 13
  • 15
1
  1. Store a boolean in SharedPreferences (SP) called hasRunOnce set it to a default of false.
  2. In onCreate and inside an if clause for which the SP hasRunOnce must be false, store current time in milliseconds (System.currentTimeMillis() will work but you'll need to cast the Long) to an Integer in SharedPreferences called installTime and set the SP hasRunOnce to true (so we'll never again re-store the system time).
  3. In onCreate (or onResume) and inside of an if clause for which the current system time must be greater than installTime plus 24 * 60 * 60 * 1000 (a day's worth of milliseconds), put in the logic to make your Button view visible.
JASON G PETERSON
  • 2,193
  • 1
  • 18
  • 19
0

Your first doing getting system time and app first running time. before I advice your look up this two links

get android current time

get app first running time

and your make if condition on your activity it seems

if(sysDateTime - appFirstRunTime > 24){
   yourButton.visiblty = true;
Community
  • 1
  • 1
erdema
  • 1