我正在尝试使用
Context.getSystemService(Context.ACTIVITY_SERVICE)
获取topActivity
类onKeyDown
方法中的phonewindow.java
。但我被告知"java.lang.SecurityException: Permission Denial: getTasks()"
,如何更改权限或我的代码是否正确?< / p>
下面是我的代码
protected boolean onKeyDown(int featureId, int keyCode, KeyEvent event) {
Context mContext;
mContext = getContext();
ActivityManager mActivityManager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
ComponentName mCName = mActivityManager.getRunningTasks(1).get(0).topActivity;
String ActivityName = mCName.getClassName().toString();
Log.d(TAG, "PackageName is " + ActivityName);
...
}
答案 0 :(得分:0)
<uses-permission android:name="android.permission.GET_TASKS" >
</uses-permission>