我想在按钮单击时打开 android 屏幕,现在我为此编写了一个程序,没有显示任何错误,也没有工作..
代码是..
public class MainActivity extends Activity {
Button powerOff;
int amountOfTime =20*1000;
Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
powerOff = (Button)findViewById(R.id.button1);
powerOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
PowerManager.WakeLock mWLock;
try {
System.out.println("Enter try Block");
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mWLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, "WakeLock");
mWLock.acquire();
} catch(Exception e) {
Log.e("ScreenLock", "onStart()::acquire() failed " + e.toString());
}
}
});
}
我想锁屏,怎么办???