The code below works successfully on Android 4.4, but since android 5.1 getRunningAppProcesses () return only own process. How can I check if the application is running on Android> 5.1?
static boolean isRun(Context context, String pkg_name) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
    if (procInfos == null)
        return false;
    int i;
    for (i = 0; i < procInfos.size(); i++) {
        ActivityManager.RunningAppProcessInfo proc = procInfos.get(i);
        if (proc.processName.equals(pkg_name))
            return true;
    }
    return false;
}
What to use instead of getRunningAppProcesses () for Android 5.1 and above.
 
    