我知道如何实现一个 BroadcastReceiver
来通知一个新的呼出电话正在开始。
我也知道如何最终挂断电话并在应用程序中处理它。
我想知道的是问用户丢不丢靠谱吗?
据我所知,应用程序从 RroadcastReceiver
返回的时间有限。
这次有多长?
你实现过吗?
编辑
尝试实现它我意识到有一个更大的问题。在 BroadcastReceiver
中,您无法显示对话框。形成文档:
In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use
Context.startService()
to send a command to the service.
原因是你不能执行AsyncTask
。我以为我要使用信号来实现它,但你不能这样做,因为广播接收器是在主线程中启动的,你不能让它等待......
这样对吗?
最佳答案
As far as I know the application has a limited amount of time to return from the BroadcastReceiver. How long is this time?
正式来说,这个时间大约是 5 秒 - 5 秒后。当系统主线程无法处理系统消息时,Android 应该抛出 ANR(应用程序无响应)对话框并强制关闭您的应用程序。
更一般性 - BroadcastReceiver onReceive()
方法应该尽快完成。
如果您想向用户显示一些 UI 元素,我认为您应该为此目的启动您自己的 Activity
。
关于android - 为 android.intent.action.NEW_OUTGOING_CALL 注册广播接收器并询问用户要做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9397082/