如何获得耳机插拔耳机电脑重启状态节点

没有更多推荐了,
不良信息举报
举报内容:
Android4.2耳机插拔检测实现方法
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!今天在做项目的时候,需要对耳机的插拔事件进行监听,所以就写了如下的一个小demo,对耳机监听事件进行验证。直接看代码
package com.example.
import android.content.BroadcastR
import android.content.C
import android.content.I
import android.util.L
import android.widget.T
public class HeadsetPlugReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
int state = intent.getIntExtra("state", -1);
int mic = intent.getIntExtra("microphone", -1);
if(state==0 && mic ==0){
Log.e("123", "headset no microphone not connected");
Toast.makeText(context, "headset no microphone not connected", Toast.LENGTH_LONG).show();
} else if (state==0 && mic ==1) {
Log.e("123", "headset with microphone not connected");
Toast.makeText(context, "headset with microphone not connected", Toast.LENGTH_LONG).show();
}else if(state==1 && mic ==0){
Log.e("123", "headset no microphone connected");
Toast.makeText(context, "headset no microphone connected", Toast.LENGTH_LONG).show();
} else if (state==1 && mic ==1) {
Log.e("123", "headset with microphone connected");
Toast.makeText(context, "headset with microphone connected", Toast.LENGTH_LONG).show();
对于广播在activity中的注册什么的,我们就不写了,毕竟大家都知道
监听的广播是
filter.addAction("android.intent.action.HEADSET_PLUG");
直接看我们的打印log
1.进入应用-&插入耳机-&拔出耳机(带有麦克风)
1 09-17 10:43:02.815: E/123(32136): headset no microphone not connected
2 09-17 10:43:29.285: E/123(32136): headset no microphone connected
3 09-17 10:43:29.355: E/123(32136): headset with microphone connected
4 09-17 10:43:41.965: E/123(32136): headset with microphone not connected
5 09-17 10:43:42.995: E/123(32136): headset no microphone not connected
2.插入耳机-&进入应用-&拔出耳机(带有麦克风)
1 09-17 10:50:49.635: E/123(32136): headset with microphone connected
2 09-17 10:51:01.995: E/123(32136): headset with microphone not connected
3 09-17 10:51:03.025: E/123(32136): headset no microphone not connected
3.进入应用-&插入耳机-&拔出耳机(没有麦克风)
1 09-17 11:10:34.665: E/123(3542): headset no microphone not connected
2 09-17 11:10:38.985: E/123(3542): headset no microphone connected
3 09-17 11:10:49.945: E/123(3542): headset with microphone connected
4 09-17 11:10:50.635: E/123(3542): headset with microphone not connected
5 09-17 11:10:51.635: E/123(3542): headset no microphone not connected
4.插入耳机-&进入应用-&拔出耳机(没有麦克风)
1 09-17 11:03:27.815: E/123(2838): headset no microphone not connected
2 09-17 11:03:30.865: E/123(2838): headset no microphone connected
从上面的结果我们可以得出如下的结论
1)监听有线耳机(有无麦克风)的广播 是 Intent.ACTION_HEADSET_PLUG
2)刚进入这个应用,会对耳机进行监听的,不明白为什么,但至少可以作为一次初始条件判断
3)这个广播可以同时监听插入的耳机是有线还是无线。不过,似乎是有线跟无线插入都会对有线跟无线进行判断,会发两次广播
4)state-耳机插入状态0-拔出 1-插入
&&&& microphone-有无麦克风 0-没有 1-有
阅读(...) 评论()您还可以使用以下方式登录
当前位置:&>&&>& > 手机耳机接口插拔识别解决方案
手机耳机接口插拔识别解决方案
      The audio jack has become standard in smart phone applications.These jacks allow the user to either plug a headset with a microphone (4 pole) or stereo headphones (3 pole).The current system design allows the mobile phone to detect between 3 or 4 pole and Send/End key, but the design has inherent issues with power, detection errors, and pop-n-click.These issues in functionality and audio quality can result in a poor user experience.Fairchild’s new audio jack detection switches provide an interface between the audio jack, baseband processor, and microphone preamp.These new devices automatically detect what is plugged into the audio jack, resolve software issues, drastically reduce system current, reduces PCB space, and eliminate pop-n-click caused by the microphone bias.  The Current Solution:  The current audio jack detection solution is designed with discrete components, typically a comparator with supporting resistors and capacitors (see Figure 1).This design has inherent flaws, these flaws result in user interface issues wasted current, and audio pop-n-click.The comparator in the circuit is utiliz one to detect between a 3 pole (stereo headphones) or 4 pole (headset with microphone) audio plug, two detect a Send/End key push.If a 3 pole plug is inserted the mic line is pulled to GND, the comparator outputs a Low to the baseband.When a 4 pole plug is connected the mic line typically is 1.8V with no Send/End key press.When the Send/End key is pressed it shorts the mic line to ground and the comparator outputs a s Low to the baseband.This causes a fundamental issue if a 4 pole headset is connected while pushing the Send/End key the baseband registers a 3 Pole jack, and the system may never recover.Additionally, this design increases current consumption in two significant areas.The resistor divider used to set the comparators voltage reference is connected directly to the supply, which continuously drains about 28&A (I2 on Figure 1) even when there is no audio plug.The Mic bias is not isolated based on the system settings.If a 4 pole plug is connected and the mic is not required the Mic bias drains &500uA (I1 on Figure 1) through the RMIC and Microphone.Not gating the Mic bias also creates a pop-n-click issue.The mic line is typically the fourth pole in the audio jack, when the plug is inserted or removed the left and right speaker terminals scrape across the mic bias, causing pop-n-click.All of these issues cause increased system design & software time to try to mitigate them, and a poor user experience.   Figure 1 – Current Audio Jack Detection Design  Audio Jack Detection Switches:  Mobile phone manufacturers increased scrutiny on the user experience has resulted in a audio jack detection switches.Devices such as the FSA8008 interface between the audio jack, baseband, mic preamp (Figure 2).These detection switches focus on resolving the issues of the current solution, while providing further features such as: board space savings, increased ESD performance, simple baseband interfaces, and automatic reset.   Figure 2 – Audio Jack Detection Switch Solution  Solve Stuck Send/End Key Issue:  When a user plugs in a headset and holds the Send/End key the phone errors and recognizes a 4 pole headset as a 3 pole stereo headphones.In this mode the mic preamp will be muted or off and the headset microphone will not function.Further, the phone will never recover from this state creating a poor user experience.Audio jack detection switches like the FSA8008 resolve this issue by continuously monitoring the mic bias line voltage when a3 pole jack is detected.If a 3 pole plug is ever detected, proprietary circuitry in the FSA8008 close the switch connecting the Mic bias voltage to the 4th pole of the audio jack for a short duration.If the mic line voltage equals ground a 3 pole is still connected, but if the mic line voltage is above 200mV it is a 4 pole headset.The device will recognize this change and output the update on the JPOLE pin to the baseband.The phone will recover from the error, and the microphone will be functional.This solution solves poor user experience by automatically correcting the error and updating the system.  Reduce System Current:  The current system design is not
it wastes power in two instances.The current leakages occur with the comparator voltage reference (I2 = 28uA in Figure 1) and when the headset is connected and the microphone is not required (I1 &500uA in Figure 1).Detection switches significantly reduce system current by consolidating the comparator, voltage reference, switch, and logic into one device.In the current solution (Figure 1) the comparator and voltage reference alone represent 48&A (comparator = 20&A + voltage reference =28&A).The total worst case, max current consumption of a detection switch like the FSA8008 is 25uA, saving almost half the current of the comparator and voltage reference alone.Further, the detection switch detects when the audio plug is inserted or removed, when the plug is removed the detection switch automatically enters a low power state of 3&A max.  Understanding the mobile phone’s current operation can further reduce current.For example in MP3 mode the Send/End key can be used for play and pause, but the microphone is not required.In the current solution, the mic line bias is required to identify the Send/End key push.The mic line bias creates leakage current greater than 500uA through RMIC and the microphone.Audio jack detection switches can reduce this current by monitoring for a Send/End key push.Human interfaces like the Send/End key input only require hundreds of milliseconds of accuracy. This allows the detection switch to only need to monitor the Send/End key for a short duration of time.To monitor the Send/End key the internal switch is closed, the mic line bias is measured for a Send/End key push or not.If a key push is detected the Send/End key is debounced and the baseband is notified.If no key push is detected, the internal switch is opened.The duty cycle of this monitor is 90 / 10, saving 90% of the system power over the current solution.  Eliminate Pop-n-Click caused by Microphone Bias  Depending on the design the mic line maybe connected to the 3rd or 4th pole of the audio jack.In either case if the mic bias voltage is present when the audio plug is inserted or removed pop-n-click will be heard, creating a poor user experience.The left and right speakers are connected to the 1st and 2nd poles respectfully and when inserting or removing the plug these poles will scrape past the mic bias voltage causing the pop-n-click.Audio jack detection switches like the FSA8008 have all the components to fully eliminate this issue.The device includes the audio plug insert or removal detection pin (J_DET), the switch to isolate the mic line bias, and the debounce circuitry.When the audio plug is inserted, the J_DET pin detects the connection and the internal logic debounces the manual connection.After the debounce is completed, the baseband will be notified of the connection and the internal switch can be closed.When the audio plug is removed the detection switch must react quickly to isolate the mic line bias before the R SPKR (Right Speaker) contacts the GND (ground) internal to the audio jack.In this case the detection switch recognizes the audio plug removal, quickly debounces the connection, and opens the switch.Integrating these three features into the detection switch allows the devices to fully resolve the pop-n-click from the mic bias issue.  The new device type of audio jack detection devices, resolve inherent issues with the current system solution.These devices can improve the user experience and system design by eliminating pop-n-click, reducing leakage current, and resolving detection errors.以上是用户分享关于手机耳机接口插拔识别解决方案的资料希望对您有所帮助了,感谢您对就爱阅读的支持!
欢迎转载:
相关推荐:如何获得耳机插拔状态节点_百度知道
如何获得耳机插拔状态节点
我有更好的答案
如果系统动态定义耳机插拔状态是没问题的,但是如果想静态定义在manifest.xml中,这是并没有得到耳机插拔状态,所以有些情况下不想启用应用的方式来检测耳机状态,而是系统实时想检测耳机状态 ,下列方法可以获得耳机状态。
标签标识系列产品全球供应商
主营:打印耗材、标签机、电子元器件、电脑周边配件的购销、维修
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 android 耳机插拔事件 的文章

 

随机推荐