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.
精彩评论