//获取当前的Activity名称 package.classname
private String getTopActivity(Activity context){
ActivityManager am= (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTasks = am.getRunningTasks(1);
RunningTaskInfo rti = runningTasks.get(0);
ComponentName cn = rti.topActivity;
Log.v("offline", "getClassName = " + cn.getClassName());//包名+类名
Log.v("offline", "getShortClassName = " + cn.getShortClassName());//类名
Log.v("offline", "getPackageName = " + cn.getPackageName());//包名
return cn.getClassName();
}
少不了权限:
<!-- 获取activity名称 -->
<uses-permission android:name = "android.permission.GET_TASKS"/>
时间: 2024-10-10 09:52:25