2

How do I track how long an application has been installed on a device?

If i use a shared preference, the data is cleared. Any ideas?

VicVu
  • 6,655
  • 5
  • 50
  • 89
Mehul Tank
  • 195
  • 13

1 Answers1

3

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)

Community
  • 1
  • 1
Todor Kostov
  • 1,597
  • 1
  • 11
  • 19
  • Ya You are Right But i don't want how many time app is run you say it is given to me whenever app is run that time count increase ..but i want know how much time app is installed in device. so when ever app is installed in device at that time only call to server and store in database – Mehul Tank Sep 15 '16 at 14:07
  • 2
    You only send that information once. The very very very first time the app was launch. In order the determine if the current launch of the app is the very first one, you can use SharedPreferences and save a flag there if the app had been launch already. – Todor Kostov Sep 15 '16 at 14:09
  • @ Todor Kostov ya You are also right but user if clear data then also preference is also cleared then also increases count .. i want to know how many time application install i.e first time install app that time count is 1 then uninstall again install that time count will be increases by 1 that will be 2 – Mehul Tank Sep 15 '16 at 14:12
  • 2
    I used @TodorKostov idea with the flag in `SharedPreferences`. It works. Off course, if the user clear the data, you lose the flag. But if the user delete the file too... There is no place you could save a file without keeping it lock to the user. – AxelH Sep 15 '16 at 14:14
  • 2
    you can send `PackageInfo.firstInstallTime` with it, as an de-duplication key – njzk2 Sep 15 '16 at 14:41
  • @njzk2 I am not getting properly please tell me in detail what you are saying – Mehul Tank Sep 15 '16 at 14:52
  • 2
    Todor suggests you send the IMEI. You say that's not good enough because you can send it again if the user clears the data. I suggest you send the first install time, which will allow you to identify unique installations. – njzk2 Sep 15 '16 at 15:02
  • @njzk2 ya you are right but how to identify is first time installation – Mehul Tank Sep 17 '16 at 13:14
  • you don't need to care about that. then the server the information, and let it sort it out. send IMEI + timestamp, the server saves it, if it receives it a second time with the same pair, just ignore it. – njzk2 Sep 17 '16 at 13:39