欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Calling a method in the system process without a qualified user

程序员文章站 2022-07-14 15:05:42
...

问题描述: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