gpt4 book ai didi

android - 如何检测耳机功能

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:44:44 24 4
gpt4 key购买 nike

我知道如何 detect whether a headset is plugged in但有些耳机(例如三星 EHS60ANNBE)带有暂停/播放(又名 KeyEvent。KEYCODE_HEADSETHOOK)按钮没有 PREV/NEXT...

我希望能够检测当前插入 Android 设备的耳机是否有 PREV/NEXT(又名 KeyEvent.KEYCODE_ MEDIA_PREVIOUS/KeyEvent.KEYCODE_ MEDIA_NEXT )。

这可能吗?

最佳答案

你在使用 BroadcastReceiver 吗?我猜你是。

来自 Android 开发人员:

public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
//receive the key press event
KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
//check the keypress
if (KeyEvent.**** == event.getKeyCode()) {
// Handle key press.
}
}
}
}

** a link with various keypress codes

关于android - 如何检测耳机功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666084/

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