Android的耳机检测 [英] Android headphone detection

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

问题描述

我有一个应用程序,会说话的短信给用户。我想使它这样,当用户点击一个名为耳机上的按钮,应用程序将只把它检测到耳机时说。是否有一个命令,让我来检测是否耳机插入或不?

I have an app that will speak text messages to the user. I want to make it so that when the user hits a button called "Headphones on" the app will only speak to it when headphones are detected. Is there a command that will allow me to detect if headphones are plugged in or not?

推荐答案

有一个广播制作时,插入耳机:的http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG

There is a broadcast made when the headphones are plugged in: http://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG

您需要注册一个广播接收器来接受这一点,并执行您所需的操作。

You need to register a BroadcastReceiver to receive this and perform your required actions.

这篇关于Android的耳机检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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