前言
简单记录下Android中监听Settings.System中值变化,记录于此,方便自己查阅和回顾。
正文
开发中,获取当前亮度值:
int light = Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, -1);
key值为Settings.System.SCREEN_BRIGHTNESS。
private final ContentObserver mBrightness = new ContentObserver(new Handler(Looper.getMainLooper())) { public void onChange(boolean selfChange) { int light = Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, -1); Log.d(TAG, "onChangeX light : "+ light); } };
设置监听
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS), true, mBrightness);
参考文章
《
© 版权声明