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