user6763460
user6763460

Reputation:

Detect and get name of an app launched

I've read all the solutions about this topic on stack and I've tried all the solutions, but still I have not found anything about my problem.

Is there any way to detect from a service when an app, I don't know package, is launched?

I need something like:

Thanks

Upvotes: 0

Views: 61

Answers (1)

user4571931
user4571931

Reputation:

Hii You can try this in your service which will check every one second for the current app, prior lollipop you will use this code,

final ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
mActivityManager.getRunningTasks(1).get(0).topActivity.getPackageName();

Upvotes: 1

Related Questions