检测缺乏耳机(只扬声器)在Android设备上 [英] Detect lack of earpiece (speakerphone only) on an Android device

查看:143
本文介绍了检测缺乏耳机(只扬声器)在Android设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序在手机上使用时,它会显示一个扬声器切换按钮。拨动开关手机的听筒和扬声器之间的音频路由。然而,当应用程序被运行在一个片剂(或缺少一个听筒的任何装置),我希望移除肘节,因为所有的音频通过扬声器路由

I've got an app which displays a speakerphone toggle button when used on a phone. The toggle switches audio routing between the phone's earpiece and the speakerphone. However, when the app is run on a tablet (or any device which lacks an earpiece), I'd like to remove the toggle, since all audio is routed through the speakerphone.

在理想情况下,我想使用某种类型的 isEarpiece present的()通话,或者检查一个标志,一些配置对象上找到这些信息,但我找不到API中诸如此类的事。

Ideally, I'd like to use some kind of isEarpiecePresent() call, or maybe check a flag on some configuration object to find this information, but I can't find anything of the sort in the API.

我试图通过调用来解决这个问题 AudioManager.setSpeakerphoneOn(假),然后选中 AudioManager.isSpeakerphoneOn(),希望它仍然会返回true,我可以键关机了这一点。该系统返回,即使声音通过扬声器还是路由。

I attempted to work around the issue by calling AudioManager.setSpeakerphoneOn(false), then checking AudioManager.isSpeakerphoneOn(), hoping that it would still return true and I could key off of that. The system returned false, even though audio is still routing through the speaker.

目前,我正在想检查电话能力,尽管这并不完全适合。任何其他的想法?

I'm currently thinking of checking for telephony capability, even though that doesn't exactly fit. Any other ideas?

推荐答案

我研究过这一点,可惜我找不到检测耳机是否存在任何API的支持。

I've researched this and unfortunately I can't find any API support for detecting whether an earpiece exists.

我现在已经提出了这个与谷歌作为一个功能要求:
HTTP://$c$c.google.com/p /安卓/问题/详细信息?ID = 37623

I've now raised this with Google as a feature request:
http://code.google.com/p/android/issues/detail?id=37623

如果您同意此功能,请点击星在谷歌问题,页面底部选它!

If you agree with the feature, click on the star at the bottom of the Google issue page to vote for it!

很多用户都提出了这个问题,谷歌Talk不提供扬声器/听筒切换选项,这或许表明不存在一个合适的API ...
HTTP://$c$c.google.com/p /安卓/问题/详细信息?ID = 19221

Lots of users have raised the issue that Google Talk doesn't offer a speaker/earpiece toggle option, which perhaps suggests the absence of a suitable API...
http://code.google.com/p/android/issues/detail?id=19221

作为一种变通方法,您可能希望隐藏由(所有这些方法都有缺点)近似设备的功能:

As a workaround you may wish to hide the feature on devices approximated by (all of these approaches have drawbacks):

  • 在那些拥有超大屏幕(即平板电脑)
  • 在那些没有电话支持
  • 使用没有耳机的主要设备的配置的白/黑名单。

FTR,如果你使用这个答案路由音频耳机,也似乎没有任何负面侧面影响运行在Xoom的(OS 3.1)或三星Galaxy Tab是code(OS 2.2) - 音频只是继续通过外置扬声器播放。我还没有机会测试,如果有任何的互动与蓝牙耳机呢。

FTR, if you use this answer to route audio to the earpiece, there don't seem to be any negative side affects running that code on the Xoom (OS 3.1) or the Samsung Galaxy Tab (OS 2.2) - the audio just continues to play through the external speaker. I haven't had a chance to test if there are any interactions with Bluetooth headsets yet.

这篇关于检测缺乏耳机(只扬声器)在Android设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆