I need to get package name or app name of any app when it gets opened by user. I searched about this but didn't get proper example.
Anyone can give me suggestions for this case? Thank you so much.!
I need to get package name or app name of any app when it gets opened by user. I searched about this but didn't get proper example.
Anyone can give me suggestions for this case? Thank you so much.!
You have to create your background service for that , which will continuously monitor top app in device .
So first of all make a service which will start after your app launch .In your service , use this
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
activityOnTop=ar.topActivity.getClassName();
activityOnTop will give you the current running app in your phone . Now do whatever you want after getting top activity.