I found this method to get the foreground activity:
public String getRecentActivity(Context context) { //I cut out the pre API 22 part of the method if (