2014年9月27日 星期六

[android] 抓top activity 名稱


private String getTopActivity() {
        ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        if (am == null) {
            Log.d(TAG,"Go() am = null");
            return null;
        }
        // get the info from the currently running task
        List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);

        //Log.d("topActivity", "CURRENT Activity ::"
        //        + taskInfo.get(0).topActivity.getClassName());

        ComponentName componentInfo = taskInfo.get(0).topActivity;
        //Log.d(TAG, "getPackageName = " + componentInfo.getPackageName());
        return componentInfo.getPackageName();
    }

沒有留言:

張貼留言