gpt4 book ai didi

android - react native : catch volume buttons press (not for volume adjusting)

转载 作者:可可西里 更新时间:2023-11-01 06:13:20 28 4
gpt4 key购买 nike

如何检测在 iOS/Android 上是否按下了 +- 按钮?

最佳答案

我认为它对 iOS 有帮助..

 - (void)viewWillAppear:(BOOL)animated {

AVAudioSession* audioSession = [AVAudioSession sharedInstance];

[audioSession setActive:YES error:nil];
[audioSession addObserver:self
forKeyPath:@"outputVolume"
options:0
context:nil];
}

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

if ([keyPath isEqual:@"outputVolume"]) {
NSLog(@"volume changed");
}
}

还有安卓。

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (action == KeyEvent.ACTION_DOWN) {
//TODO
}
return true;
default:
return super.dispatchKeyEvent(event);
}
}

关于android - react native : catch volume buttons press (not for volume adjusting),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43361599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com