Call end listener in Android
I am developing an application in which I am storing call log details from CallLog
provider.
Android stores call logs in a database and I am copying new rows from that database.
Now I want to copy call details when the user ends a call. For that I have 开发者_如何学运维used the PhoneStateListener
with which I listen for state ringing, off hook and idle mode
but after the call is ended the idle method calls more than once, so I cannot use that.
Second I used ContentObserver
for call log table and it gives me onChanged event when Android inserts call details in it and at that time I copy those details into my database.
Is it that the proper way to use ContentObserver
?
Is there any other way to get details of new calls which is just ended?
That sounds like a valid use of the ContentObserver
. A prior attempt at this is here: Intent to be fired when a call ends?.
I'd suggest you go with the idle method and simply track state in a database or variable or preference (so whenever the phone goes from OFFHOOK to IDLE you know the call ended, but when it goes from IDLE to IDLE then you do nothing).
Good luck.
精彩评论