安卓:检查是否插入耳机 [英] Android: Checking if headphones are plugged in

查看:137
本文介绍了安卓:检查是否插入耳机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查是否插入耳机,在目前堵塞。我不想一个BroadcastReceiver它告诉我,当他们已经​​连接到设备上。我需要的是这样的:

 如果(/ *耳机连接* /)
 ...
 

解决方案

看起来你会感兴趣的<一个href="http://developer.android.com/intl/de/reference/android/media/AudioManager.html#isWiredHeadsetOn%28%29"><$c$c>isWiredHeadsetOn()法和<一href="http://developer.android.com/intl/de/reference/android/media/AudioManager.html#isBluetoothA2dpOn%28%29"><$c$c>isBluetoothA2dpOn()方法 <一个href="http://developer.android.com/intl/de/reference/android/media/AudioManager.html"><$c$c>AudioManager类。

不过, isWiredHeadsetOn()方法仅适用于Android的2.0或更高版本可用。 (该 isBluetoothA2dpOn()方法由于Android 1.5可用。)

How can I check if headphones are currently plugged in. I don't want a broadcastreceiver which informs me when they have been connected to the device. I need something like:

if(/*headphone is connected*/)
 ...

解决方案

It looks like you'll be interested in the isWiredHeadsetOn() method and isBluetoothA2dpOn() method of the AudioManager class.

However, the isWiredHeadsetOn() method is only available in Android 2.0 or later. (The isBluetoothA2dpOn() method has been available since Android 1.5.)

这篇关于安卓:检查是否插入耳机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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