是否有FLAG_RECEIVER_REGISTERED_ONLY,解决方法只使用一个BroadcastReceiver是什么时候? [英] Is there a workaround for FLAG_RECEIVER_REGISTERED_ONLY, when using only a BroadcastReceiver?

查看:721
本文介绍了是否有FLAG_RECEIVER_REGISTERED_ONLY,解决方法只使用一个BroadcastReceiver是什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要被警告,如果一个耳机插入,但意图ACTION_HEADSET_PLUG用于与旗FLAG_RECEIVER_REGISTERED_ONLY。
所以我要运行一个服务或所有活动的时间,以获得意图是什么?我只是想在所有运行一个BroadcastReceiver和NO的服务或活动。对此有一个解决方法吗?这甚至可能?或者,我可以一次启动服务,登记,然后停止它?

I want to be alerted, if a headset is plugged in. But the Intent "ACTION_HEADSET_PLUG" is used with the Flag "FLAG_RECEIVER_REGISTERED_ONLY". So I have to run a service or a activity all the time to get the intent? I just want to run a Broadcastreceiver and NO service or activity at all. Is there a workaround for this? Is this even possible? Or can I start a service once, registering and then stopping it?

P.S:我知道,当耳机与嘈杂成为插入的意图了。

P.S.: I know when the headset is plugged off with the becoming noisy intent.

感谢您为你解答。

推荐答案

戴安娜Hackborn说

这只是给那些谁打电话registerReceiver,而不是发送到
  在清单中声明的​​接收器。

It's only given to those who call registerReceiver, and not sent to receivers declared in manifests.

所以,你必须有一些正在运行的调用 registerReceiver 。它的停止运行,你不注销,你得到一个错误的接收器。

So you have to have something running that calls registerReceiver. It that stops running and you don't unregister the receiver you get an error.

这篇关于是否有FLAG_RECEIVER_REGISTERED_ONLY,解决方法只使用一个BroadcastReceiver是什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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