I'm trying to get an Android background service to be "notified" when the user chooses a phone number (he wishes to call) from the phone's contacts list. My goal with this is to prevent the system from placing the call and present a user with a choice dialog, then go from there... Need help.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
I found a way to do what I asked yesterday, so I'm sharing it here for anyone interested. The trick was, to catch the NEW_OUTGOING_CALL broadcasted intent in a BroadcastReceiver and not any event related to the choosing of contacts, as I was thinking.
So... follow the steps.
In the application element of the AndroidManifest.xml file add a receiver element... The android:name attribute is the class that will extend from BroadcastReceiver (explained below).
ahh! And you'll need a special permission...
The onReceive method in the class that extends BroadcastReceiver (OutgoingCallDetection in this example). Note that setResultData(null) is what prevents the call from being made by the system itself.
Here it is, and working as needed.