第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

想問下有沒有其他方法,還是我的實(shí)現(xiàn)有問題?

想問下有沒有其他方法,還是我的實(shí)現(xiàn)有問題?

慕斯王 2022-10-11 15:11:45
休眠的過程是屏幕先變灰再變黑,想要實(shí)現(xiàn)在自動(dòng)休眠灰屏?xí)r,點(diǎn)擊后(屏幕會(huì)變亮)實(shí)現(xiàn)一些操作。試了以下兩種方案:1、注冊(cè)SCREEN_BRIGHTNESS廣播,嘗試獲取屏幕的變化,無果,應(yīng)該是android自身沒有發(fā)送對(duì)應(yīng)的廣播消息2、點(diǎn)擊時(shí)獲取系統(tǒng)的亮度值,(通過oldBrightness = getInt(getContentResolver(), SCREEN_BRIGHTNESS);)但發(fā)現(xiàn)還是255,即還是亮,所以無法判斷。
查看完整描述

2 回答

?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊

系統(tǒng)會(huì)發(fā)送廣播
Intent.ACTION_SCREEN_OFF

Intent.ACTION_SCREEN_ON

Intent.ACTION_USER_PRESENT

查看完整回答
反對(duì) 回復(fù) 2022-10-16
?
白衣染霜花

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊

捕捉自動(dòng)休眠灰屏的事件,可以通過監(jiān)聽系統(tǒng)的廣播獲得當(dāng)前手機(jī)屏幕的狀態(tài),廣播需要在注冊(cè)文件中注冊(cè),具體的實(shí)現(xiàn)代碼如下:

  public class ScreenListener {
private Context mContext;
private ScreenBroadcastReceiver mScreenReceiver;
private ScreenStateListener mScreenStateListener;

public ScreenListener(Context context) {
mContext = context;
mScreenReceiver = new ScreenBroadcastReceiver();
}

/**
* screen狀態(tài)廣播接收者
*/
private class ScreenBroadcastReceiver extends BroadcastReceiver {
private String action = null;

@Override
public void onReceive(Context context, Intent intent) {
action = intent.getAction();
if (Intent.ACTION_SCREEN_ON.equals(action)) { // 開屏
mScreenStateListener.onScreenOn();
} else if (Intent.ACTION_SCREEN_OFF.equals(action)) { // 鎖屏
mScreenStateListener.onScreenOff();
} else if (Intent.ACTION_USER_PRESENT.equals(action)) { // 解鎖
mScreenStateListener.onUserPresent();
}
}
}

/**
* 開始監(jiān)聽screen狀態(tài)
*
* @param listener
*/
public void begin(ScreenStateListener listener) {
mScreenStateListener = listener;
registerListener();
getScreenState();
}

/**
* 獲取screen狀態(tài)
*/
private void getScreenState() {
PowerManager manager = (PowerManager) mContext
.getSystemService(Context.POWER_SERVICE);
if (manager.isScreenOn()) {
if (mScreenStateListener != null) {
mScreenStateListener.onScreenOn();
}
} else {
if (mScreenStateListener != null) {
mScreenStateListener.onScreenOff();
}
}
}

/**
* 停止screen狀態(tài)監(jiān)聽
*/
public void unregisterListener() {
mContext.unregisterReceiver(mScreenReceiver);
}

/**
* 啟動(dòng)screen狀態(tài)廣播接收器
*/
private void registerListener() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
mContext.registerReceiver(mScreenReceiver, filter);
}

public interface ScreenStateListener {// 返回給調(diào)用者屏幕狀態(tài)信息
public void onScreenOn();

public void onScreenOff();

public void onUserPresent();
}
}

在上面的代碼中,用到了動(dòng)態(tài)注冊(cè)廣播,在需要監(jiān)聽屏幕狀態(tài)的activity中,當(dāng)不需要監(jiān)聽的時(shí)候,如activity finish的時(shí)候,使用unregisterListener解除廣播監(jiān)聽;
下面是在Activity中調(diào)用;
  ScreenListener l = new ScreenListener(this);
l.begin(new ScreenStateListener() {

@Override
public void onUserPresent() {
Log.e("onUserPresent", "onUserPresent");
}

@Override
public void onScreenOn() {
Log.e("onScreenOn", "onScreenOn");
}

@Override
public void onScreenOff() {
Log.e("onScreenOff", "onScreenOff");
}
});

  通過以上步驟即實(shí)現(xiàn)了對(duì)屏幕狀態(tài)的監(jiān)聽.


查看完整回答
反對(duì) 回復(fù) 2022-10-16
  • 2 回答
  • 0 關(guān)注
  • 264 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)