Android Question Get forground apps on Android 5+

Devv

Active Member
Licensed User
Longtime User
I was using this to get foreground

B4X:
Sub GetPackagename As String
    Dim ActMan As JavaObject
    Dim R As Reflector
    R.Target=R.GetContext
    'Get Activity Manager Object
    ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
    Dim TaskInfo As JavaObject = ActMan.RunMethod("getRunningTasks",Array As Object(1))
    Dim CompInfo As JavaObject = TaskInfo.RunMethodJO("get",Array As Object(0)).GetField("topActivity")
    Dim PackageName As String = CompInfo.RunMethod("getPackageName",Null)

    Return PackageName
End Sub


it is no longer working for android 5+
after doing a small online research i found that google stopped it after android 5.x

these guy here had made a solution in java
https://stackoverflow.com/questions...cesses-returns-my-application-packag/33034556


Anyone know a working way on Android 5.x or could convert that java code to B4A ?
 

DonManfred

Expert
Licensed User
Longtime User
As you can read there too:
Starting with android 5.1.1 it no longer works. Dont work in android 6 too
 
Upvote 0
Top