关于本地/远程服务、广播接收器和意图服务的结构问题
我正在编写一个具有标准活动的 Android 应用程序,但也需要随时监控传入/传出电话和短信。此外,应用程序需要每天向用户通知一次信息,而无需打开活动。它通知用户的信息存储在数据库中,因此不需要与活动进行通信。我已经研究了一个星期,但仍然无法决定如何去做。我的直觉告诉我,我需要一个具有持续运行的广播接收器的远程服务,但我看到的每个远程服务示例都过于复杂。谁能帮助我更好地了解我需要采取哪些步骤?提前致谢。
I'm writing an android app that has a standard activity, but also needs to monitor incoming/outgoing calls and texts at all times. In addition, the app needs to notify users of information once a day without having the activity open. The information it notifies users of is stored in a database, so communication with the activity is not necessary. I've been researching for a week and still can't decide how to go about doing this. My instinct tells me I need a remote service that has a constantly running broadcast receiver, but every remote service example I see is overly complicated. Could anyone help me better understand what steps I need to take? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
,嗯,不。我这么说是因为:
使用清单中注册的
BroadcastReceivers
来进行随时可能发生的广播,因为即使您的应用程序没有其他内容正在运行。使用IntentService
执行这些BroadcastReceiver
所需的任何“繁重工作”,因为BroadcastReceiver
获得控制权(在onReceive() 中)
)在主应用程序线程上,因此应该做尽可能少的工作。另外,使用AlarmManager
向BroadcastReceiver
(或者可能是您的IntentService
)发出信号,为您发出Notification
每日一次的活动。另外,请注意,您无法“监视...传出...文本”,并且“监视...传入...文本”需要您使用 Android 的未记录功能。虽然可能
android.provider.Telephony
不会消失,但您只需要意识到所涉及的风险即可。Um, no. I say that, because:
Use
BroadcastReceivers
registered in your manifest for broadcasts that can occur at any time, as they will get control even if nothing else of your application is running. Use anIntentService
for doing any "heavy lifting" that is needed by thoseBroadcastReceivers
, asBroadcastReceiver
get control (inonReceive()
) on the main application thread and therefore should do as little work as possible. Also, useAlarmManager
to signal aBroadcastReceiver
(or, possibly, yourIntentService
) to raise aNotification
for your once-daily event.Also, please be advised that there is no way for you to "monitor...outgoing...texts", and that to "monitor...incoming...texts" requires you to use an undocumented capability of Android. While probably
android.provider.Telephony
will not be going away, you just need to be aware of the risk involved.