简体   繁体   English

如何确认嵌入的设备(运行Android OS)是否有扬声器

[英]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.

相关问题 检查Android设备是否有内置扬声器 - Check if Android device has an internal speaker 如何检查Android设备是否具有在10.2或更高版本上运行的Google Play服务 - How to check the whether the android device has google play services running on 10.2 or greater 如何找出android设备是否有蜂窝无线电模块? - How to find out whether android device has cellular radio module? 如何检查 android 设备是否支持 gps? - How to check whether an android device has gps support or not? 如何判断一个android设备是否有硬键 - How to tell whether an android device has hard keys 如何检查在移动Android设备或台式机Android设备(Android-x86 OS)上运行的android应用? - How to check a android app is running on mobile android device or desktop android device(Android-x86 OS)? 应用程序未在Android设备上运行(Tablet OS 4.0.3) - App Not Running on Android Device (Tablet OS 4.0.3) 如何知道设备是否有数据连接? - How to know whether device has data connection? 如何确定Android设备是否有屏幕,即它是否是Android机顶盒? - How to determine if an Android device has a screen i.e. whether it is an Android set top box? 如何确认Android应用是DeepLink启动还是正常启动? - How to confirm whether Android app is launched by DeepLink or normal launch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM