Calling a method in the system process without a qualified user

Posted 兔子夹心脆

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Calling a method in the system process without a qualified user相关的知识,希望对你有一定的参考价值。

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

以上是关于Calling a method in the system process without a qualified user的主要内容,如果未能解决你的问题,请参考以下文章

Android代码异常Calling a method in the system process without a qualified user

Android代码异常Calling a method in the system process without a qualified user

C++: How is the process of function calling in C++

TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution o

The supplied data appears to be in the Office 2007+ XML.You are calling the part of POI that deals w

JAVA calling convention