問題描述: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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/293383.html
標籤:其他
