Android/Xamarin: 如何启动与广播接收器的对话

Android/Xamarin: How to launch dialog with broadcast receiver

我想让我的应用程序监听呼叫应用程序广播的意图,当针对特定号码广播呼叫意图时,我想启动一个对话。我读到 "A broadcast receiver may not display dialogs, and it is strongly discouraged to start an activity from within a broadcast receiver" https://developer.xamarin.com/guides/android/application_fundamentals/broadcast-receivers/ 所以我假设我应该让广播接收器启动一个服务,然后启动一个对话框。谁能证实这一点?也将不胜感激任何简化的例子

谢谢!

在下面的示例中,应用程序使用 BroadcastReceiver 来检测 phone 来电号码并决定是否应接听:

How to reject incoming call programatically in android?

因此使用 BroadcastReceiver 并没有那么糟糕。

如果您只想显示有关 phone 调用的信息,您可以按照 Jon Douglas 在评论中的建议显示通知。不允许显示来自 BroadcastReceivers 的对话框(也不鼓励)。