Android Question get package name on android 5

ArminKH

Well-Known Member
Hello every body
I am going to develop an app which is a security app like locker apps
By using this app we can lock each place of our phone such as gallery,file manager,etc...
Now i want to Get package name for every app which is started by user and must be unlocked after user entered correct pass or pattern ,...
Here is my code
B4X:
Dim R As Reflector
    R.Target=R.GetContext
    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)
Log(PackageName)
By using this code we can get package name for each running app but not worked on android +5 without any error and just return luncher package name
Tnx all
 

DonManfred

Expert
Licensed User
Longtime User
Did you set the right permissions in manifest? Maybe
B4X:
AddPermission(android.permission.GET_TASKS) ' Allows an application to get information about the currently or recently running tasks.
 
Upvote 0

ArminKH

Well-Known Member
Did you set the right permissions in manifest? Maybe
B4X:
AddPermission(android.permission.GET_TASKS) ' Allows an application to get information about the currently or recently running tasks.
Yes but still not worked
 
Upvote 0

ArminKH

Well-Known Member
In Android L, Google has disabled getRunningTasks. Now it can only return own apps task and the home launcher.

There are a few workarounds:
http://stackoverflow.com/questions/24625936/getrunningtasks-doesnt-work-in-android-l

http://stackoverflow.com/questions/...tive-for-getrunningtask-api/27304318#27304318
Have u the corect code which is working on android +5?
If is possible please correct my code for android +5
I'm not so much familar with java and reflection methods
 
Upvote 0

sonicmayne

Member
Licensed User
Longtime User
It seems like Google really really doesn't want you getting other application's information, such as this.

I couldn't get the UsageStatsManager way of getting package names working, only the getRunningAppProcesses. This works on Android L, but does not work on Android M.
 
Upvote 0
Top