Reputation:
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
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