//获取当前的Activity名称 package.classname

private String getTopActivity(Activity context){

 ActivityManager am= (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

       

      List 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();

}


少不了权限: