开发者

Send button/Volume button Action listeners

开发者 https://www.devze.com 2023-02-10 00:35 出处:网络
developing for Android phone(ver 1.5) I would like to know if there is an option to a开发者_如何学Pythondd listener when long-press Send button occurs. and also the same question about voulme-mute act

developing for Android phone(ver 1.5) I would like to know if there is an option to a开发者_如何学Pythondd listener when long-press Send button occurs. and also the same question about voulme-mute action ?

thanks, ray.


Since you're using a pretty early version of the API, there is one method which could be sueful for you, KeyEvent.getDownTime().

public boolean onKey(View v, int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_CALL && event.getDownTime() > 1000){
    // Long call key event
  }else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
    AudioManager m = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); // changing 'this' for your context instance
    int vol = m.getStreamVolume(AudioManager.STREAM_SYSTEM); // using your desired stream type
    if (vol == 0){
      // Is the volume switched off?
    }
}

Of course you have to set to your view the OnKeyListener by the setOnKeyListener method:

myView.setOnKeyListener(this);

and implement the OnKeyListener interface in the class you like.

0

精彩评论

暂无评论...
验证码 换一张
取 消