2

I am developing app locker application for all the versions. It's working in pre lollipop version but not working in lollipop version.

I am getting all the running application in lollipop version but i want to find which application is opened.

source for running application: https://github.com/jaredrummler/AndroidProcesses/

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pri M
  • 11
  • 1
  • 4

2 Answers2

0

If i correctly understand, you try to determine current foreground application. Try this.

Community
  • 1
  • 1
Artur Szymański
  • 1,639
  • 1
  • 19
  • 22
0

This should provide you the package name of currently running application:

    ActivityManager activityManager = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
    String packageName = "";

    if(Build.VERSION.SDK_INT > 20){
     packageName = mActivityManager.getRunningAppProcesses().get(0).processName;
    } else {
     packageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
    }
Mohib Irshad
  • 1,940
  • 23
  • 18
  • Hii thanks for your answer already i used this solution but it's working in 5.1 nexus emulator not working in some real devices and 23 version – Pri M Oct 22 '15 at 14:45