这种情况下如何做服务呢?
所以我有一个类可以监听来电,我想为我的所有应用程序提供一项服务来接收呼叫,即使我不在应用程序的用户界面中也是如此。 如何触发这个类(广播接收者)。我使用“sendBroadcast”并且有一个FC。
sendBroadcast(new Intent(context, IncomingCallReceiver.class));
感谢您的帮助。
So i have a class that listens to incoming calls, i want to make a service to all my app to receive calls even when i'm not in the application's UI.
How to trigger this class(broadcast receiver). I used "sendBroadcast" and have a FC.
sendBroadcast(new Intent(context, IncomingCallReceiver.class));
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的情况下,我将使用以下方法:
Service
并从您的Activity
启动它(您提到您有多个应用程序,因此启动其中第一个应用程序也可能会启动服务)。registerReceiver()
为您想要监控的 Intent 注册它。onReceive()
中调用一些服务函数。例如,您可以使用您的应用程序识别的一些自定义 Intent 来 sendBroadcast() 。unregisterReceiver()
取消注册 BroadcastReceiver 扩展。更新:
In your case I would use the following approach:
Service
and start it from yourActivity
(you mentioned that you have several applications, so starting first of them may also start the Service).stopSelf()
. Please note that also System may terminate your Service and prevent it from working forever.registerReceiver()
.onReceive()
. For example, you may sendBroadcast() using some custom Intent that is recognized by your applications.unregisterReceiver()
.UPDATE: