Reputation: 1502
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.
Upvotes: 0
Views: 2456
Reputation: 900
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();
}
Upvotes: 2