发送键/音量按钮动作监听器 [英] Send button/Volume button Action listeners
本文介绍了发送键/音量按钮动作监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
开发Android手机(版本1.5) 我想知道是否有一个选项,添加侦听器时长preSS发送按钮时发生。同时也对电压快速静音操作同样的问题?
developing for Android phone(ver 1.5) I would like to know if there is an option to add listener when long-press Send button occurs. and also the same question about voulme-mute action ?
谢谢, 射线。
推荐答案
由于您使用API的pretty的早期版本,有可能是sueful你一种方法,KeyEvent.getDownTime()。
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?
}
}
当然,你必须设置为您的视图中的 OnKeyListener
的 setOnKeyListener
方法:
myView.setOnKeyListener(this);
和实现你喜欢的类OnKeyListener接口。
and implement the OnKeyListener interface in the class you like.
这篇关于发送键/音量按钮动作监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文