Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.List; import android.app.ActivityManager; import android.app.ActivityManager.RunningTaskInfo; import android.content.ComponentName; import android.content.Context; public class Main { public static final String getTopAppPackageName(final Context context) { String packageName = null; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> list = am.getRunningTasks(1); ComponentName comp = list.get(0).topActivity; if (null != comp) { packageName = comp.getPackageName(); } return packageName; } }