Seeing which app is currently running

123 Views Asked by At

I have created an app which starts a service which is constantly looking to what the current activity is. It display the names of all the activities in my app properly, but any other apps are com.android.launcher2.Launcher. I was wondering if it was actually possible to see what the current actiivty is.

1

There are 1 best solutions below

0
On
public class Services extends Service{

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();

        for(;;)
        {   
            for(RunningAppProcessInfo info : runningAppProcessInfo)
            {
                Log.d("APP", info.processName);
            }
        }

    }

}