0

I want my app to listen for intends broadcasted by the call application, and when a call intend is broadcasted for a specific number I want to launch a dialog. I read that "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/ so I am assuming I should instead make the broadcast receiver launch a service that then launches a dialog. Can anyone confirm this? Also any simplified examples would be highly appreciated

Thanks!

Maja Okholm
  • 3,147
  • 2
  • 11
  • 17
  • 2
    I wouldn't do this via a `Service` either. You should really consider using a `Notification` for this instead. Other options might be a transparent `Activity`, but that's pretty hacky. – Jon Douglas Mar 30 '17 at 19:03

1 Answers1

1

In the example below, the app uses a BroadcastReceiver to detect a phone call number and decide whether it should answer or not:

How to reject incoming call programatically in android?

So using a BroadcastReceiver for that isn't that bad.

If you just want to show information about the phone call, you can display an Notification, as suggested by Jon Douglas in the comments. Displaying Dialogs from BroadcastReceivers isn't allowed (also disencouraged).

Community
  • 1
  • 1
Alexandre
  • 565
  • 3
  • 9