本文介绍了的UserManager getUserCount()(果冻豆)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的这个类:的UserManager
I am working on this class : UserManager
public int getUserCount ()
返回在设备上当前创建的用户的数量。
Return the number of users currently created on the device.
我的code是:
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.
清单文件:
<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>
推荐答案
在 MANAGE_USERS
的签名的的ProtectionLevel |系统
,这意味着应用程序必须与平台密钥签署。请参见在XDA这个线程
The MANAGE_USERS
has a protectionlevel of signature|system
, which means that the application has to be signed with the platform key. See this thread on XDA
这篇关于的UserManager getUserCount()(果冻豆)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!