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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Android上關閉屏幕

在Android上關閉屏幕

千萬里不及你 2019-09-02 16:55:12
我試圖在某個動作發(fā)生后打開和關閉顯示器(讓我們擔心暫時關閉屏幕)。根據(jù)我對喚醒鎖的理解,這就是我所擁有的:PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");當我在stackoverflow上閱讀其他帖子時,他們似乎告訴我PARTIAL_WAKE_LOCK將關閉屏幕。但是,如果我閱讀SDK,它會說它只允許屏幕關閉。所以我覺得這不對。任何提示都會有所幫助!謝謝,
查看完整描述

3 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

關閉屏幕有兩種選擇:


PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);


// Choice 1

manager.goToSleep(int amountOfTime);


// Choice 2

PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Your Tag");

wl.acquire();

wl.release();

您可能也需要此權限:


<uses-permission android:name="android.permission.WAKE_LOCK" />

更新:


試試這個方法; 一旦光線足夠低,android會關閉屏幕。


WindowManager.LayoutParams params = getWindow().getAttributes();

params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;

params.screenBrightness = 0;

getWindow().setAttributes(params);


查看完整回答
反對 回復 2019-09-02
?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

以下內容從SDK文檔中復制。如果你想保持屏幕,我認為SCREEN_BRIGHT_WAKE_LOCK就足夠了。


Flag Value                CPU   Screen  Keyboard

PARTIAL_WAKE_LOCK          On*    Off      Off


SCREEN_DIM_WAKE_LOCK       On     Dim      Off


SCREEN_BRIGHT_WAKE_LOCK    On     Bright   Off


FULL_WAKE_LOCK             On     Bright   Bright


查看完整回答
反對 回復 2019-09-02
?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

對我來說,這些方法不起作用。所以我使用其他場景(不是微不足道)來關閉我的屏幕。


Android有2個標志,負責清醒:


顯示 - >屏幕TimeOut

應用程序 - >開發(fā) - > 充電時保持清醒復選框。

我使用了以下流程:


首先保存您之前的配置,例如屏幕超時為1分鐘,并 在充電時保持清醒狀態(tài)。


之后,我取消選中充電時保持清醒并將屏幕超時設置為最短時間。


我注冊廣播接收器服務從屏幕關閉的Android獲取事件。


當我關閉屏幕上的事件時,我將先前的配置設置為默認值:屏幕超時為1分鐘并且 在檢查充電時保持清醒狀態(tài)。


取消注冊接收器


15秒后 設備睡覺


這是代碼片段:


廣播接收器


import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;


/**

 * Catch Screen On/Off

 * */

public class BroadcastReceiverScreenListener extends BroadcastReceiver{


private BroadCastListenerCallBackItf mBroadCastListenerCallBack = null;


public BroadcastReceiverScreenListener(

        BroadCastListenerCallBackItf broadCastListenerCallBack) {

    this.mBroadCastListenerCallBack = broadCastListenerCallBack;

}


@Override

public void onReceive(Context arg0, Intent intent) {



    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {

        mBroadCastListenerCallBack.broadCastListenerCallBack__ScreenOff_onResponse();

    }       

}


}

用作回調的接口


public interface BroadCastListenerCallBackItf {

    public void broadCastListenerCallBack__ScreenOff_onResponse();

}

主類2種方法:


....


AndroidSynchronize mSync = new AndroidSynchronize();


....


public void turnScreenOff(int wait){

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);

    filter.addAction(Intent.ACTION_SCREEN_OFF);


    BroadCastListenerCallBackItf broadCastListenerCallBack = this;


    BroadcastReceiver mReceiver = new BroadcastReceiverScreenListener(broadCastListenerCallBack);       

    m_context.registerReceiver(mReceiver, filter);




    //set Development --> disable STAY_ON_WHILE_PLUGGED_IN

    Settings.System.putInt(

            m_context.getContentResolver(), 

            Settings.System.STAY_ON_WHILE_PLUGGED_IN,

            0                                );




    // take current screen off time 

    int defTimeOut = Settings.System.getInt(m_context.getContentResolver(), 

            Settings.System.SCREEN_OFF_TIMEOUT, 3000);

    // set 15 sec

    Settings.System.putInt(m_context.getContentResolver(), 

            Settings.System.SCREEN_OFF_TIMEOUT, 15000);


    // wait 200 sec till get response from BroadcastReceiver on Screen Off

    mSync.doWait(wait*1000);



    // set previous settings

    Settings.System.putInt(m_context.getContentResolver(), 

            Settings.System.SCREEN_OFF_TIMEOUT, defTimeOut);


    // switch back previous state

    Settings.System.putInt(

            m_context.getContentResolver(), 

            Settings.System.STAY_ON_WHILE_PLUGGED_IN,

            BatteryManager.BATTERY_PLUGGED_USB);



    m_context.unregisterReceiver(mReceiver);



}






public void broadCastListenerCallBack__ScreenOff_onResponse() {

    mSync.doNotify();

}


....

AndroidSynchronize類


public class AndroidSynchronize {


    public void doWait(long l){

        synchronized(this){

            try {

                this.wait(l);

            } catch(InterruptedException e) {

            }

        }

    }       


    public void doNotify() {

        synchronized(this) {

            this.notify();

        }

    }   


    public void doWait() {

        synchronized(this){

            try {

                this.wait();

            } catch(InterruptedException e) {

            }

        }

    }

}

[編輯]


您需要注冊權限:


android.permission.WRITE_SETTINGS


查看完整回答
反對 回復 2019-09-02
  • 3 回答
  • 0 關注
  • 976 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號