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?
Asked
Active
Viewed 588 times
1
-
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 Answers
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
- Store a boolean in
SharedPreferences(SP) calledhasRunOnceset it to a default offalse. - In
onCreateand inside anifclause for which the SPhasRunOncemust be false, store current time in milliseconds (System.currentTimeMillis()will work but you'll need to cast theLong) to an Integer inSharedPreferencescalledinstallTimeand set the SPhasRunOncetotrue(so we'll never again re-store the system time). - In
onCreate(oronResume) and inside of anifclause for which the current system time must be greater thaninstallTimeplus 24 * 60 * 60 * 1000 (a day's worth of milliseconds), put in the logic to make yourButtonview 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
and your make if condition on your activity it seems
if(sysDateTime - appFirstRunTime > 24){
yourButton.visiblty = true;