0

I see that question: How can i check if an app running in Android?

But i want to get name of opened application ( user see ) live in android.

I want to run a background service to check that.

Community
  • 1
  • 1

1 Answers1

2

You can get the running Application package name using this function:

public String foregroundPackage() {
        ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
        ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
        packageName = componentInfo.getPackageName();
        return componentInfo.getPackageName();
    }
Mateus Brandao
  • 900
  • 5
  • 9