1. How to get incoming call number in android (Broadcast receiver for incoming number)?
2. How to get outgoing call number in android (Broadcast receiver for outgoing number)?
3. How to know call is ended or not in android?
4. How to get call log details after ending call in android?
5. How to create and use SQLite Data Base in android?
6. How to fire Content Observer after ending call?
I had worked a lot with phone state and spend time and money to know what exactly android doing. Now I am here with working code and going to share with all coders.
I am using broadcast receiver to know state of the phone and get incoming and outgoing number. Phone has three states:
1. Ringing: call is coming.
2. Idle: inactive or call disconnected.
3. Offhook: active state.
We can easily detect phone state and can know when call is ending using idle state and get new call log details but we can face any problems which are listing below:
1. Idle state call once again after idle state sometime (or in some device).
2. Idle state call in between Offhook state sometime (or in some device).
3. Call ended but call log not created yet and we queried to fetch new call log information and get wrong result sometime.
Hmm… Problems can create new problem(s). But After lot of research, finally I solved all the problems and used Content Observer to keep track on changes in call logs and use if condition to solve call end problem. Now Content Observer is creating a new problem and calling many times and giving single and exact call details multiple times. Using if condition this problem is also solved.
I used simple XML layout to show call log details: your_project -> res -> layout -> activity_main.xml
Now i used 4 Java files:-
1. MainActivity.java : To display result.
2. PhListener.java : To listen phone state.
3. DBHelper.java : To store call log details in database.
4. History.java : To fire content observer to keep track on changes in call log.
Now change AndroidManifast.xml file and define all necessary permissions.
Now run your code and check android project. If you have any problems feel free to ask me. Share if you like this post and don’t forget to leave valuable comment regarding call log details android post or this website. Github link of this project: Android Call Log Details
1. Access Call, Camera, Web pages
2. Use SQLite Database
3. Use Shared Preferences
4. Print numbers from 1 to 100 in ScrollView
5. Create Menu using XML