BroadcastReceiver的耳机中拔出

编程入门 行业动态 更新时间:2024-10-25 10:25:42
本文介绍了BroadcastReceiver的耳机中拔出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好我的工作产生过当耳机从手机中删除的事件的应用程序。 我创建了一个广播接收器与接收方法

Hi i am working on an application that generate an event when ever the headphone is removed from the mobile phone. I have created a broadcast receiver with receive method as

public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); Log.i("Broadcast Receiver", "Hello"); if( (actionpareTo(Intent.ACTION_HEADSET_PLUG)) == 0) //if the action match a headset one { int headSetState = intent.getIntExtra("state", 0); //get the headset state property int hasMicrophone = intent.getIntExtra("microphone", 0);//get the headset microphone property if( (headSetState == 0) && (hasMicrophone == 0)) //headset was unplugged & has no microphone { //do whatever } } }

调用此方法如下:

Calling this method as follows

IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); HeadSetBroadCastReceiver receiver = new HeadSetBroadCastReceiver(); registerReceiver( receiver, receiverFilter );

另外我有登记本中表现为

also i have register this in manifest as

<receiver android:name=".HeadsetBroadCastReceiver"> <intent-filter> <action android:name="android.intent.action.ACTION_HEADSET_PLUG"/> </intent-filter> </receiver>

和许可

但是,这不列入工程任何人都可以指导我通过这个?

But this doesnot works can anyone guide me through this?

推荐答案

这里的问题是,这个braodcast具有标志 Intent.FLAG_RECEIVER_REGISTERED_ONLY设定。这意味着清单recivers不会赶上这一点。 Here是一个完整的explenation。

Problem here is that this braodcast has flag Intent.FLAG_RECEIVER_REGISTERED_ONLY set. This means that manifest recivers will not catch that. Here is a full explenation.

更多推荐

BroadcastReceiver的耳机中拔出

本文发布于:2023-11-05 04:10:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:耳机   BroadcastReceiver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!