简介
在开发中,遇到Calling a method in the system process without a qualified user这样的错误
原因:在Android 4.2以后,增加了多用户,需要使用如下发送广播
context.sendBroadcastAsUser(intent,UserHandle.ALL);
添加权限
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
但是会发现UserHandle获取不到UserHandle.ALL,查看源码
public final class UserHandle implements Parcelable {
// NOTE: keep logic in sync with system/core/libcutils/multiuser.c
/**
* @hide Range of uids allocated for a user.
*/
@UnsupportedAppUsage
public static final int PER_USER_RANGE = 100000;
/** @hide A user id to indicate all users on the device */
@UnsupportedAppUsage
public static final @User