3

I am working on this class : UserManager

public int getUserCount ()

Return the number of users currently created on the device.

My code is:

UserManager um = (UserManager) getSystemService(USER_SERVICE);
int count = um.getUserCount();
Log.i("count",""+count);

It produce error like this:

 Caused by: java.lang.SecurityException: You need MANAGE_USERS permission to: query users
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.os.Parcel.readException(Parcel.java:1379)
    at android.os.IUserManager$Stub$Proxy.getUsers(IUserManager.java:321)
    at android.os.UserManager.getUsers(UserManager.java:198)
    at android.os.UserManager.getUserCount(UserManager.java:186)
    at com.example.multiusertest.MainActivity.onCreate(MainActivity.java:52)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

I already added this permission manually in Manifest file. Does anyone know why it is produce.

Manifest File:

<uses-sdk
    android:minSdkVersion="17"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.MANAGE_USERS"/>

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

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

4

1 回答 1

3

MANAGE_USERS保护级别为signature|system,这意味着必须使用平台密钥对应用程序进行签名。在 XDA 上查看此线程

于 2012-11-22T12:11:36.133 回答