使用如下方法可以获得top activity 的name
public String getTopActivityPackageName(Context context) {
String topActivityPackage = null;
ActivityManager activityManager = (ActivityManager) (context
.getSystemService(android.content.Context.ACTIVITY_SERVICE));
List<RunningTaskInfo> runningTaskInfos = activityManager
.getRunningTasks(1);
if (runningTaskInfos != null) {
ComponentName f = runningTaskInfos.get(0).topActivity;
topActivityPackage = f.getPackageName();
}
return topActivityPackage;
}
时间: 2024-10-11 04:51:28