AndroidManifest.xml加权限:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
Activity处理:
public class Main extends Activity {
public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);
setContentView(R.layout.main);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// KeyEvent.KEYCODE_HOME KeyEvent.KEYCODE_APP_SWITCH
if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)
return true;
else
return super.onKeyDown(keyCode, event);
}
}
时间: 2024-10-27 12:00:27