Reputation: 200486
I'd like to have some code be notified of any incoming and outgoing voice calls. I need to grab all the following:
It would also be really slick if I could get more contact info, specifically the contact name, if the phone number matches up to someone in the phone's contacts list, but that part is optional.
I need my code to get this information pretty much as soon as a call has ended. Maybe I'm just not searching for the correct terms but I'm having a real hard time finding any examples of how I would accomplish this.
If someone could provide a code example that accomplishes this, along with the permissions and any sort of broadcast receiver type of setup I would need in the manifest file, that would be great.
Upvotes: 2
Views: 7484
Reputation: 111555
You should be able to directly watch outgoing calls by listening for android.intent.action.NEW_OUTGOING_CALL
broadcast events, by setting the android.permission.PROCESS_OUTGOING_CALLS
permission in your manifest.
I imagine this should work for other devices; at least on my HTC Hero this gives me an Intent
full of extras including the phone number being called, the contact's name plus URIs for the contact and individual number being called.
As for getting full information on incoming or missed calls (and indeed outgoing calls), I believe the solution as Mark mentions is to watch the CallLog
content provider for changes, or poll after the relevant PhoneStateListener
events have been fired.
Upvotes: 6
Reputation: 1006604
A PhoneStateListener
and the CallLog
content provider will give you most, if not all, of what you need.
Upvotes: 2