问题描述:android framework中修改代码,每次屏幕亮度发生变化的时候发送广播,发送广播使用如下代码进行发送:
Intent intent = new Intent();
intent.setAction("com.android.server.light.brightness");
intent.putExtra("brightness", brightness);
//send broadcast
mContext.sendBroadcast(intent);
运行后logcat打印如下错误信息:
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:966 com.android.server.lights.LightsService$LightImpl.setBrightness:63 com.android.server.display.LocalDisplayAdapter$LocalDisplayDevice$1.setDisplayBrightness:534 com.android.server.display.LocalDisplayAdapter$LocalDisplayDevice$1.run:488 com.android.server.display.DisplayManagerService.requestGlobalDisplayStateInternal:478
解决方法:参考以下博客;
https://blog.csdn.net/jdsjlzx/article/details/38779355
大概意思就是Android 4.2以后加入了多用户
改换这几种调用方式
//导入相应包
import android.os.UserHandle;
Intent intent = new Intent();
intent.setAction("com.android.server.light.brightness");
intent.putExtra("brightness", brightness);
//send broadcast
getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
public void startActivityAsUser(Intent intent, UserHandle user);
public void sendBroadcastAsUser(Intent intent, UserHandle user);
public ComponentName startServiceAsUser(Intent service, UserHandle user);
public boolean stopServiceAsUser(Intent service, UserHandle user);
UserHandle.ALL
UserHandle.CURRENT
UserHandle.CURRENT_OR_SELF
UserHandle.OWNER

在Android框架中,当屏幕亮度变化时发送广播出现错误:'Calling a method in the system process without a qualified user'。此问题源于Android 4.2引入的多用户功能。解决方案包括使用startActivityAsUser、sendBroadcastAsUser、startServiceAsUser和stopServiceAsUser方法,并指定UserHandle,如UserHandle.ALL、UserHandle.CURRENT、UserHandle.CURRENT_OR_SELF和UserHandle.OWNER。

7620

被折叠的 条评论
为什么被折叠?



