i'm currently setting up an automation on my Android device and i need to know which activity is currently in the foreground so i can include it in the automation as a trigger. I'm looking for the app activity withing the whole package
Thanks
i'm currently setting up an automation on my Android device and i need to know which activity is currently in the foreground so i can include it in the automation as a trigger. I'm looking for the app activity withing the whole package
Thanks
Sure, use Activity Manager.
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();
You will need the following permission on your manifest:
<uses-permission android:name="android.permission.GET_TASKS"/>