2 분 소요

화면을 끄는건… 아래에 있는 내용을 찾아보면 될듯하다.

http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#screenBrightness

결국 아래 함수의 인자를 0으로 주고 호출하면.. 화면이 잘 꺼진다..

public void setBright(float value) {

Window mywindow = getWindow();

WindowManager.LayoutParams lp = mywindow.getAttributes();

lp.screenBrightness = value;

mywindow.setAttributes(lp);

}

—————————– java —————————————-

package com.sulac.ProximitySensor;

import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.os.PowerManager;

import android.view.View;

import android.view.Window;

import android.view.WindowManager;

import android.widget.Button;

public class ProximitySensorActivity extends Activity {

Button btn;

/-* Called when the activity is first created. *-

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

btn = (Button)findViewById(R.id.button1);

btn.setText(“StartTest”);

btn.setOnClickListener(new View.OnClickListener(){

public void onClick(View v){

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

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, “DoNotDimScreen”);

btn.setText(“listen”);

setBright(0);

}

});

}

public void setBright(float value) {

Window mywindow = getWindow();

WindowManager.LayoutParams lp = mywindow.getAttributes();

lp.screenBrightness = value;

mywindow.setAttributes(lp);

}

}


아래는.. naver로 찾다가 엄한걸로 삽질한 내용이다. 모.. 결국 이 내용은 화면 끄는걸 방지하거나 CPU가 죽는걸 방지하는 기능을 보여주는 걸로 보인다.

쩝.. 아래는.. sleep에 안들어 가게 하는 방법이다.. 이런 바부.. ㅜㅜ

이건.. Mp3 Player 만들때.. sleep들어가도 안꺼지게 만들때 쓰면 될듯하다..

——– java code ——

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

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, “DoNotDimScreen”);

wl.acquire();

——– manifest ———

http://developer.android.com/reference/android/os/PowerManager.html

Class Overview

This class gives you control of the power state of the device.

Device battery life will be significantly affected by the use of this API. Do not acquire WakeLocks unless you really need them, use the minimum levels possible, and be sure to release it as soon as you can.

You can obtain an instance of this class by calling Context.getSystemService().

The primary API you’ll use is newWakeLock(). This will create a PowerManager.WakeLock object. You can then use methods on this object to control the power state of the device. In practice it’s quite simple:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire();   ..screen will stay on during this section.. wl.release(); 

The following flags are defined, with varying effects on system power. These flags are mutually exclusive - you may only specify one of them.

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

*If you hold a partial wakelock, the CPU will continue to run, irrespective of any timers and even after the user presses the power button. In all other wakelocks, the CPU will run, but the user can still put the device to sleep using the power button.

In addition, you can add two more flags, which affect behavior of the screen only. These flags have no effect when combined with aPARTIAL_WAKE_LOCK.

Flag Value Description
ACQUIRE_CAUSES_WAKEUP Normal wake locks don’t actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.
ON_AFTER_RELEASE If this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions.

Any application using a WakeLock must request the android.permission.WAKE_LOCK permission in an <uses-permission> element of the application’s manifest.