方法一:
public class UnLockActivity2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}
方法二:
public class UnLockActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
m_wklk = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "cn");
m_wklk.acquire();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
m_wklk.release();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
m_wklk.release();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
m_wklk = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "cn");
m_wklk.acquire();
}
WakeLock m_wklk;
}
<uses-permission android:name="android.permission.WAKE_LOCK" />
参考:
http://www.cnblogs.com/king_dy/archive/2010/11/11/1888134.html