//获取当前的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"/>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。