i'm developing an android app that retrieves the call log and store it in a text file. I'm using the ContentObserver to observe for the changes and fetch the updated entry once there is a change. I'm able to fetch the entries correctly if i get a miss call, incoming call and make an outgoing call by dialing the number from the phone book. If i make an outgoing call by clicking the number from the call log, the onChange() method is called thrice. The onChange() is called once i select the name from the call log, before making a call, such that retrieving the previous event once. Once the call is made, the outgoing event is retrieved twice, totally making three entries. Please do suggest me a solution.
Thanks!
In which URI did u register the observer. Is it android.provider.CallLog.Calls.CONTENT_URI? If so then the onChange() method will be called only once.
Also, relying in content providers is not a good idea. Refer http://android-developers.blogspot.com/2010/05/be-careful-with-content-providers.html. Instead of using content observers you can try using broadcast receiver with actions
android.intent.action.PHONE_STATE
android.intent.action.NEW_OUTGOING_CALL
Related
The docs state that this service performs call identification to
display a user-interface of their choosing which contains identifying information for a call.
but i cannot find any method to do this.
I set up a call screening service overriding the onScreenCall method and I am able to get the incoming call phone number and get a caller id (if it exists in my database) but cant get it to show on the call ui
My app makes frequent use of the following pattern:
User clicks button
API request is fired
response is parsed
Callback returns data Data is updated in view.
However, due to the nature of the API these callbacks can take some time and I find that I can easily crash the app if I navigate around the app at a high pace. Mostly this is caused by NullPointerExceptions related to the fact that the activity and/or fragment no longer exists. My question is what the best practice is when dealing with these issues. Should I just check for null values everywhere? I've read somewhere that you should just avoid using callbacks to update the UI at all but I'm not sure what the alternative is.
Thank you all!
for Fragment you can check by isAdded()
public void onResponse(){
if(isAdded()){
// Do your stuff here
}
}
In activity isFinishing()
public void onResponse(){
if(!isFinishing()){
// Do your stuff here
}
}
Let me share how I did in one of my apps.
I created a class which extends Application and that class is responsible to initiate a database. It is Singleton Static database and everytime I need to do something, I call db.getInstance().doSomething()
When any API method is called, I start an AssyncTask which store the data on database after completed (in case of failure, nothing is saved).
When Database is updated, it sends a LocalBroadcast. You can send broadcasts to notify the error (which stops the Refresh animation and show a error message, for example).
Each activity has a BroadcastReceiver which register to receive the local broadcast sent by Database. I register during onStart() and de-register during onStop(). Each activity register to proper event (since you can create multiples intents and actions... This way, your activity receives only the desired intent and not every single broadcast of your app.
This way, when the activity is opened, it checks the data from database and if any content change, it receives a broadcast notification and take proper actions.
When the activity is closed, it no longer receive broadcast.. However, the updated data will be there on database after download is completed.
You must handle situations where some API call was already started to avoid calling twice (at least, until first call of same method finishes etc)..
You can also use ContentObserver to monitor some database etc.
This is one way to handle. It may work or not for you case etc... Just sharing since it may help you
How to get call log history for individual contacts, incoming calls and out going calls separately and call log history for particular date in calender programmatically?
Please refer to my answer provided on this post for accessing call log history. You can get the outgoing and incoming call logs and use them accordingly
I am trying to hide call logs from particular contact. For this I have created broadcast receiver for receive event of incoming / outgoing / missed call / call hangup.
But how can I get call details on call hangup event ?
I know we can get following 2 informations when incoming event occurs :
1) State
2) Phone Number
Now for hide contact, I need to delete entry from defalut call log database which is located in “content://call_log/calls”., and insert it inside my sqlite database.
Is there anybody who faced this kind of issue before ? Any help will be appreciated.
Thanks.
Perhaps a better approach would be to register a ContentOberver on the call log table. See this question: How to implement a ContentObserver for call logs
Whenever an update is made to the table, you could query for the phone number in question and delete the record.
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.