Android Question get installation date of an app

samfaber

New Member
Licensed User
Longtime User
Hi,
is there a possibility to find out the date of app installation?

background is that I would like to remind the user of the app with a window to it to rate the app in the Playstore.
However, this memory should not be displayed immediately after installation only after the app has been used for some days.

many thanks
Samuel


Sorry for bad english I'm German ;-)



Now I have found a solution in this thread:
http://www.b4x.com/android/forum/th...-member-from-packagemanager.16323/#post-92741

B4X:
Sub GetFirstInstallTime(Package As String) As Long
   Dim r As Reflector
   r.Target = r.GetContext
   r.Target = r.RunMethod("getPackageManager")
   r.Target = r.RunMethod3("getPackageInfo", Package, "java.lang.String", 0, "java.lang.int")
   Return r.GetField("firstInstallTime")
End Sub
 
Last edited:

ivan.tellez

Active Member
Licensed User
Longtime User
Also you can use Java Object...




B4X:
Public Sub firstInstallTime(CallingActivity As Object, PackageName As String) As String
'PackageManager.getPackageInfo(packageName, 0).firstInstallTime;
tCallingActivity = CallingActivity
Dim pm As JavaObject
Dim pInfo As JavaObject

pm = GetContext.RunMethodJO("getPackageManager", Null)
pInfo = pm.RunMethod("getPackageInfo", Array(PackageName, 0) )
Dim unixtime As Long = pInfo.GetField("firstInstallTime")

Return GetDateFromUnixMilis(unixtime)

End Sub

Public Sub lastUpdateTime(CallingActivity As Object, PackageName As String) As String
'PackageManager.getPackageInfo(packageName, 0).firstInstallTime;
tCallingActivity = CallingActivity
Dim pm As JavaObject
Dim pInfo As JavaObject

pm = GetContext.RunMethodJO("getPackageManager", Null)
pInfo = pm.RunMethod("getPackageInfo", Array(PackageName, 0) )
Dim unixtime As Long = pInfo.GetField("lastUpdateTime")

Return GetDateFromUnixMilis(unixtime)

End Sub


Private Sub GetDateFromUnixMilis(UnixTimeMilis As Long) As String

Dim targetDate As Long = DateUtils.UnixTimeToTicks(UnixTimeMilis / 1000)
DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss"
DateTime.SetTimeZone(0)
Return (DateTime.Date(targetDate))  '25.03.2014
'Return (DateTime.Time(targetDate))  '10:52:50

End Sub



Private Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

Private Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = tCallingActivity
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
The code above does not appear to work in version 2.2. An error is thrown that the field does not exist. Does anyone know a way to get the install date from 2.2 and above?
 
Upvote 0
Top