Android保持屏幕常亮唤醒状态
时间:2014-05-07 05:00:06
收藏:0
阅读:377
第一步: 首先添加权限:
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
第二步:代码实现如下:
public class ScreenActivity extends Activity { PowerManager powerManager = null; WakeLock wakeLock = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main); powerManager = (PowerManager)this.getSystemService(this.POWER_SERVICE); wakeLock = this.powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock"); } @Override protected void onResume() { super.onResume(); wakeLock.acquire(); } @Override protected void onPause() { super.onPause(); wakeLock.release(); } }最后说明:在不同的生命周期调用WakeLock函数可以使系统正常运行(如果Activity结束没有调用WakeLock.release,则屏幕会一直常亮)。
评论(0)