import android.os.PowerManager;
public class MyActivity extends Activity {
protected PowerManager.WakeLock mWakeLock;
/** Called when the activity is first created. */
@Override
public void onCreate(final Bundle icicle) {
setContentView(R.layout.main);
/* This code together with the one in onDestroy()
* will make the screen be always on until this Activity gets destroyed. */
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
this.mWakeLock.acquire();
}
@Override
public void onDestroy() {
this.mWakeLock.release();
super.onDestroy();
}
}
記得要加入以下權限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
![[Android SDK特色教學] 使用WakeLock保持螢幕清醒/螢幕恆亮 [Android SDK特色教學] 使用WakeLock保持螢幕清醒/螢幕恆亮](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDitrr0YaoUgwW-4yuveX7Ird5RJ7J6VhsBJc0ns7RJXPOwd7yBFrUqggDFmYpePSY-kjVXFvOjjBFGIjuRGbbDcQG7msjpvgOKXm-vr0Nkl78tDlU7dqfB2TMUiXp_HXxWOIhlhGcEhU/s1600/android101.jpg)
沒有留言 :
張貼留言