有知道安卓 AudioDeviceInfo.TYPE_TELEPHONY 是什么设备的吗?

2022-01-26 22:31:52 +08:00
 z1113456051

一直以来判断耳机都是 TYPE_WIRED_HEADSET 和 TYPE_WIRED_HEADPHONES 这两个类型,但是现在发现小米手机经常出现 TYPE_TELEPHONY 。

类型注释是 A device type describing the transmission of audio signals over the telephony network.

网上也找不到说具体是什么设备的。

4768 次点击
所在节点    Android
5 条回复
AkaGhost
2022-01-27 02:43:17 +08:00
虽然没接触过 Android 开发,但是试着 Google 了下
https://stackoverflow.com/questions/57822073/is-voice-call-recording-back-with-android-10-2019
The call always receives audio. The app can capture audio if it is an accessibility service. The app can capture the voice call if it is a privileged (pre-installed) app with permission CAPTURE_AUDIO_OUTPUT.

To capture the voice call's uplink (TX), downlink (RX), or both, the app must specify the audio sources MediaRecorder.AudioSource.VOICE_UPLINK or MediaRecorder.AudioSource.VOICE_DOWNLINK, and/or the device AudioDeviceInfo.TYPE_TELEPHONY.

似乎和通话有关
gam2046
2022-01-27 10:56:10 +08:00
show your code

是通过什么方法,在什么场景下,获得了这样的返回值。
z1113456051
2022-01-27 11:35:17 +08:00
@gam2046

我通过这个判断有线耳机的插入,但是小米用户反馈插入耳机无效,看日志,小米返回 TYPE_TELEPHONY 类型。

我把 TYPE_TELEPHONY 加入了判断,就会有更多用户反馈没插耳机,但是进入了耳机模式。看来这个标志不插耳机的时候也会出现。

开始怀疑是有什么互联互通的设备。但是联系用户就是 typec 转接头接耳机。不知道是不是有什么手机设置开启导致的。

AudioDeviceInfo[] devices = audioManager.getDevices(GET_DEVICES_OUTPUTS);

for (int i = 0; i < devices.length; i++) {
AudioDeviceInfo deviceInfo = devices[i];
Log.e("", "devices[" + i + "].getId = " + deviceInfo.getId() + ", getType = " + deviceInfo.getType()");

if (deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADSET
|| deviceInfo.getType() == AudioDeviceInfo.TYPE_WIRED_HEADPHONES) {
return true;
}
}
z1113456051
2022-01-27 11:45:15 +08:00
@wyf001912hp 我也查过了,看起来像是通话录音相关。
gam2046
2022-01-27 11:55:41 +08:00
@z1113456051 #3 ,唔,是否尝试过通过接受 AudioManager.ACTION_HEADSET_PLUG 广播来获得相关信息,这是 Android 推荐的方法。

另外一种比较 hack 的方法,是我从 aosp 源代码里翻到的,不太推荐,由于我开发的不是常规的 Android App ,没有 Context 对象,才采用了这个方法,绕过高版本 Android 对非公开 API 调用的检查后,调用这样的代码

https://imgtu.com/i/7X1fxS

Anyways ,推荐优先尝试广播的方式获取

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/830807

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX