Home » » Disable screen auto-dim, using PowerManager

Disable screen auto-dim, using PowerManager

Written By MR HARI on Kamis, 28 April 2011 | 08.41

The class android.os.PowerManager 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().

package com.exercise.AndroidWakeLock;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

public class AndroidWakeLock extends Activity {

WakeLock wakeLock;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

PowerManager powerManager =
(PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock =
powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK,
"Full Wake Lock");
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
wakeLock.acquire();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
wakeLock.release();
}
}


Also have to grant permission of "android.permission.WAKE_LOCK" in AndroidManifest.xml.
Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger