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.