0

I am trying to get the current running tasks on two devices with Android 5.0 and 7.0. I used this code:

mActivityManager =(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
       if(Build.VERSION.SDK_INT > 20){
                      mCurrentPackageName = mActivityManager.getRunningAppProcesses().get(0).processName;
                    }
                    else{
                        mCurrentPackageName = mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();
                }

The problem is that I get my application package but when I launch another application I get :

com.sec.android.app.launcher

I wonder why this happens because on Android 4.4 it works right.

Casper Spruit
  • 944
  • 1
  • 13
  • 31
morisson
  • 11
  • 2

1 Answers1

0

Check this answer: Android 5.1.1 and above - getRunningAppProcesses() returns my application package only

This code works for me:

if (Build.VERSION.SDK_INT < 22) { 
                runningAppProcesses = ((ActivityManager) getSystemService(ACTIVITY_SERVICE)).getRunningAppProcesses();
} else runningAppProcesses = ProcessManager.getRunningAppProcessInfo(this);
Community
  • 1
  • 1
Alexey Zatsepin
  • 1,179
  • 7
  • 14