How to get app install time from android
PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified(); //Epoch Time
Get Application Install time in Android 2.2?
Try this block. This solves your problem
PackageManager pm = getApplicationContext().getPackageManager();
try {
PackageInfo info = pm.getPackageInfo("com.google.android.googlequicksearchbox", 0);
Field field = PackageInfo.class.getField("firstInstallTime");
long timestamp = field.getLong(info);
Date date = new Date(timestamp);
Log.e("DATE", date + "");
} catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchFieldException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Install time for Android application?
When you install/update a non-protected app, it's apk file gets written to /data/app/package.name.apk
, confusingly referenced as sourceDir
(from my answer) resetting the timestamp to the current one. That's it.
How to get current date and time of App Installation date in Android
Are you sure you need
context.getPackageManager().getPackageInfo("package.com.sqlitedemo"
instead of
context.getPackageManager().getPackageInfo("com.sqlitedemo"
Get Application Installed Date on Android
or this one (API Level 9 upwards!):
long installed = context
.getPackageManager()
.getPackageInfo(context.getPackageName(), 0)
.firstInstallTime
;
how to check whether app installed first time or installing second time
you can use this pacakge
https://github.com/react-native-device-info/react-native-device-info
you can identify device unique id by
import { getUniqueId } from 'react-native-device-info';
and for flutter i found this lib
https://pub.dev/packages/device_info
then you can save this id in your database, and you can query for same id to know if app was previously installed
First Application Install time
Classic never gets old :)
private String getDateTime() {
// get date time in custom format
SimpleDateFormat sdf = new SimpleDateFormat("[yyyy/MM/dd - HH:mm:ss]");
return sdf.format(new Date(appInfo.firstInstallTime));
}
How to track how much time an app is installed on a single device
On each end every initial (first) launch of the application you can send a call to a server (your one) with the IMEI of the device and save that in a database or something else. Each time you receive the same IMEI just increase the total counts.
Here you can see what exactly is the IMEI
Here you can see how to get the IMEI of the devices you are currently interested in. (Check the accepted answer)
How to detect if app has been installed for more than a day?
As Henry mentioned, You can use shared preferences to save the date of installation, and then every time the app starts check if the current date is one day bigger than the saved date. It should look something like this:
class MainActivity : AppCompatActivity()
{
companion object
{
const val INSTALLATION_DATE_KEY = "INSTALLATION_DATE_KEY"
const val MILLIS_IN_ONE_DAY = 86_400_000L;
}
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val sharedPref = getPreferences(Context.MODE_PRIVATE) ?: return
val installationTime = sharedPref.getLong(INSTALLATION_DATE_KEY, -1L)
if (installationTime == -1L) // app run for first time
{
with(sharedPref.edit()) {
val time = System.currentTimeMillis()
Log.d("MyTag", "First run. Time = $time")
putLong(INSTALLATION_DATE_KEY, time)
commit()
}
}
else
{
if (System.currentTimeMillis() - MILLIS_IN_ONE_DAY >= installationTime)
{
Log.d("MyTag", "App installed more than one day ago")
}
else
{
Log.d("MyTag", "App installed less than one day ago")
}
}
}
}
PS. It won't be "installation" time but "first-run time". So when the user installs the app and runs it for the first time after 2 days it won't work.
Related Topics
Users Does Not Define No Argument Constructor
Android Custom View Group Delegate Addview
Android in App Purchase: Signature Verification Failed
How to Use the Android Keystore to Securely Store Arbitrary Strings
When to Request Permissions with Facebook's New Android Sdk 3.0
Avd Manager - Cannot Create Android Virtual Device
How to Mask an Edittext to Show the Dd/Mm/Yyyy Date Format
Intent Does Not Set the Camera Parameters
Buttons Not Visible on the Application. What's Wrong
Android: Scrollview VS Nestedscrollview
Stop Asynctask Doinbackground Method
Most Memory Efficient Way to Resize Bitmaps on Android
Highlighting Text Color Using HTML.Fromhtml() in Android
How to Align Android Toolbar Menu/Icons to the Left Like in Google Maps App
Android How to Runonuithread in Other Class
Accessing Google Account Id /Username via Android