[英]How to confirm embeded device(running android OS) whether has a speaker or not
I want to confirm embeded device(running android OS 5.1.1) whether has a speaker or not. 我想确认嵌入的设备(运行android OS 5.1.1)是否有扬声器。 I try AuidoManager#isSpeakerphoneOn, no matter I insert or remove speaker, it always return false。
我尝试使用AuidoManager#isSpeakerphoneOn,无论插入或删除扬声器,它始终返回false。
I'm wondering how to solve this problem. 我想知道如何解决这个问题。
You can put a to only install on devices with a way of outputting sound. 您可以将a仅安装在具有输出声音的设备上。 I don't think there is an API to tell if it currently has a speaker.
我认为没有API可以告诉您当前是否有发言人。
You can use PackageManager
class' PackageManager#hasSystemFeature(String)
to check whether the given feature is present or not at runtime. 您可以使用
PackageManager
类的PackageManager#hasSystemFeature(String)
来检查给定功能在运行时是否存在。
More specifically, you can query PackageManager#hasSystemFeature(String)
using the constant FEATURE_AUDIO_OUTPUT
which returns true if the device includes at least one form of audio output, such as speakers, audio jack or streaming over bluetooth. 更具体地说,您可以使用常量
FEATURE_AUDIO_OUTPUT
查询PackageManager#hasSystemFeature(String)
,如果设备包括至少一种形式的音频输出(例如扬声器,音频插孔或通过蓝牙流式传输PackageManager#hasSystemFeature(String)
,则返回true。
PackageManager pm = getPackageManager();
if(pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT){
// audio output device present
} else {
// no audio output device present
}
Or, you can also use the <uses-feature>
element in the AndroidManifest.xml with android:name
set to android.hardware.audio.output
and require
equals to true
which will prevent your app from being installed on devices with no audio output device. 或者,您也可以在
android:name
设置为android.hardware.audio.output
的情况下使用AndroidManifest.xml中的<uses-feature>
元素,并且require
等于true
,这将阻止您的应用安装在没有音频输出的设备上设备。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.