我只想在用户点击电源按键时显示微调器,这里是我想要的代码,当用户按下powerkeybutton时,只有特定的广播接收器调用而不是任何broadcastreciver类
public class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
public void onReceive(final Context context, final Intent intent) {
ActivityMenu.spinner.performClick();
}
}
// i want to add below this code on my reciver class
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
return true;
}
return super.onKeyDown(keyCode, event);
}
或者如果我在我的主要活动中写下这段代码
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
return true;
}
return super.onKeyDown(keyCode, event);
}
如何限制我的代码只调用此 CloseSystemDialogsIntentReceiver 广播接收器类???