FLAG_TURN_SCREEN_ON

时间:2015-12-07 09:31:12

标签: android android-activity android-annotations android-screen

我有使用FLAG_TURN_SCREEN_ON

从GCM启动的Activity

下面是代码段: -

@Override
    public void onAttachedToWindow() {

        super.onAttachedToWindow();
        addFlags();
    }

    private void addFlags() {
        //Screen On
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }

    private void clearFlags() {
        //Don't forget to clear the flags at some point in time.
        getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }    

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        if (!hasFocus) {
            clearFlags();
        }

        super.onWindowFocusChanged(hasFocus);
    }

设备唤醒后我想安排屏幕DIM(15秒后我使用AA框架)。我试着在15秒后清除Flags()但是没有改变。

@UiThread(delay = 15000)
        void dimDisplay() {
            if (!isFinishing()) {
                WindowManager.LayoutParams params = getWindow().getAttributes();
                params.screenBrightness = 0.0f;// i needed to dim the display
                getWindow().setAttributes(params);
            }
        }

用户触摸后屏幕亮度= 1

@Touch
    void container() {
        if (!isFinishing()) {
            WindowManager.LayoutParams params = getWindow().getAttributes();
            params.screenBrightness = 1f;
            getWindow().setAttributes(params);
        }
    }

您是否知道问题的更清晰解决方案..此代码DIM仅显示一次。我想避免使用已弃用的PowerManager.SCREEN_DIM_WAKE_LOCK

/** @deprecated Most applications should use
     * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead
     * of this type of wake lock, as it will be correctly managed by the platform
     * as the user moves between applications and doesn't require a special permission.
     */
    @Deprecated
    public static final int SCREEN_DIM_WAKE_LOCK = 0x00000006;

0 个答案:

没有答案