How to Get App Install Time from Android

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.getPackag‌​eName(), 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



Leave a reply



Submit