Android Question Get current running app

Multiverse app

Active Member
Licensed User
Longtime User
I want to retrieve the Package ID of current running foreground app from a service.
Is it possible?
 

Multiverse app

Active Member
Licensed User
Longtime User
Thanks, Erel
I used this code:

B4X:
Dim usm As UsageStatsManager
    usm.Initialize("")

    Dim starttime As Long
    Dim a, b As Long
    a = DateTime.TimeParse(DateTime.Time(DateTime.Now))
    b = 5 * DateTime.TicksPerSecond
    Dim orario As String = DateTime.Time( a - b )
    starttime = DateTime.TimeParse(orario)
    'starttime = DateTime.Now
    Dim endtime As Long
    endtime = DateTime.Now
  
  
    Dim usage1 As List = usm.queryUsageStats(starttime,endtime)

If usage1.Size>0 Then
    For i=0 To usage1.Size-1
    Dim us As UsageStats = usage1.Get(i)
    If us.PackageName="com.android.camera" Then LogColor(us.LastTimeUsed, Colors.Blue)
    Next
End If

The above prints on log if 'Camera' App is currently launched.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…