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 "";
}