0

This is my first StackOverflow-Post so tell me if i do something wrong :) I'm currently trying to create an "AppLock-Like" App, so I somehow need my App to know which other App has been opened or what Apps are currently running.

I've been researching all day now, trying to figure out, how to get a List (Package Names) of all currently running Apps on Android. The only way to do so seems to be the depricated getRunningAppProcesses() from the ActivityManager Class. But since its depricated, it only returns my own App, even when running as a Background Service, while other Apps are beeing opened. And the new UsageStatsManager seems to only give longterm information.

Is there even still a way to get access to that information? There are plenty of Apps in the PlayStore that somehow are able to identify when and what App is opened. Any help is welcomed, thanks already :)

I've tried so much Code, this is my last try:

public static boolean isRunningAppBanned(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

    //Print all running Apps
    for (int i = 0; i < runningAppProcessInfo.size(); i++) {
        Log.println(Log.INFO, "Running Apps", runningAppProcessInfo.get(i).processName);
    }
    
    //Check if a running App is Banned
    for (int i = 0; i < runningAppProcessInfo.size(); i++) {
        if(Database.isBanned(runningAppProcessInfo.get(i).processName)) {
            Log.println(Log.ERROR, "Banned Apps", runningAppProcessInfo.get(i).processName + "IS BANNED");
            return true;
        }
    }
    return false;
}
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
Bromanius
  • 1
  • 1

2 Answers2

0

You can get information about running processes using the ActivityManager class.

Hossein
  • 439
  • 3
  • 9
-1

Just in my case I got the list of applications installed in my phone like the way of following code lines.

public static boolean isRunningAppBanned(Context context) {
    PackageManager pm = context.getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    //Print all running Apps
    for (ApplicationInfo packageInfo : packages) {
        Log.println(Log.INFO, "Running Apps", 
        pm.getApplicationLabel(packageInfo).toString() + "\t" + packageInfo.packageName;
    }
    
    return false;
}

I hope it would be helped for you to get the list of running apps on android devices. ;-)