ActivityManager <user-permission>权限不起作用</user-permission>

时间:2013-01-05 09:35:02

标签: android android-permissions

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="per.sainik.activity"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />

<user-permission android:name="android.permission.GET_TASKS" >
</user-permission>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name=".LogViewActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


</application>

import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.util.Log;

public class LogViewActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityManager activityManager = (ActivityManager) getApplication()
            .getSystemService(ACTIVITY_SERVICE);
    Log.v("LOG_SERVICE", activityManager.getRunningTasks(1).get(0)
            .toString());
}

}

它变得异常,命名为:

01-05 14:55:05.207: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{per.sainik.activity/per.sainik.activity.LogViewActivity}: java.lang.SecurityException: Permission Denial: getTasks() from pid=334, uid=10037 requires android.permission.GET_TASKS

获得权限问题。任何帮助,将不胜感激!!

2 个答案:

答案 0 :(得分:29)

您拼错了许可。确切的权限是,

<uses-permission android:name="android.permission.GET_TASKS" >
</uses-permission>

<user-permission android:name="android.permission.GET_TASKS" >
</user-permission>

答案 1 :(得分:2)

您将单词<uses-permission >拼错为<user-permission >