I want the data of the current app which is running

29 Views Asked by At

So basically i want to develop a simple appblock app and i want to show the current name of the app. I tried a few solutions but it did not work for me. e.g activityManager was one them. Perhaphs the code are depracted for the android api.

if i run whatsapp on my device than the code should return me the name.

public static String isAppRunning(final Context context, final String packageName) {
            final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            final List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
            if (procInfos != null)
            {
                for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
                    if (processInfo.processName.equals(packageName)) {
                        return packageName;
                    }
                }
            }
            return "";
        }
0

There are 0 best solutions below