Anda di halaman 1dari 9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

Home
About us
Contact us
Privacy Policy

Tutorials
Gadgets
Internet
Technologies

Android Call Log Example Code (add, update, delete numbers


from call log)
May 15, 2013 Android Tutorial, Tutorials

Android Call Log Example (add, update, delete entries in call log)
Here we will learn how to add / delete / update entries in Android call log example code. It is very simple to
update Android call log programmatically. Only we need a small code snippet to adding and deleting entries
into/from Android call log. We will discuss how to add/delete outgoing call, missed calls and incoming calls
into/from Android call log. To make the code very simple. I have created a java class called CallLogUtility in
which i have written 2 functions (one is for add new entries into call log and other is for delete entries from the
call log). Here is the class with the java file. Just add this file in your projejcts source code and call these
functions. Call the function AddNumToCallLog(), if you want to add entries in call log. Call
the function DeleteNumFromCallLog(), if you want to delete entries from call log.
1. CallLogUtility Class
1
2
3
4
5
6
7
8
9

import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.CallLog;
import android.util.Log;

public class CallLogUtility {

publicvoidAddNumToCallLog(ContentResolver resolver ,String strNum, int type, long timeInMil

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

1/9

15/07/2015

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 }

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

while(strNum.contains("-"))
{
strNum =strNum.substring(0,strNum.indexOf('-')) + strNum.substring(strNum.indexOf
}
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, strNum);
values.put(CallLog.Calls.DATE, timeInMiliSecond);
values.put(CallLog.Calls.DURATION, 0);
values.put(CallLog.Calls.TYPE, type);
values.put(CallLog.Calls.NEW, 1);
values.put(CallLog.Calls.CACHED_NAME, "");
values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
Log.d("AddToCallLog", "Inserting call log placeholder for " + strNum);
if(null != resolver)
{
resolver.insert(CallLog.Calls.CONTENT_URI, values);
}
//getContentResolver().delete(url, where, selectionArgs)

public void DeleteNumFromCallLog(ContentResolver resolver, String strNum)


{
try
{
String strUriCalls = "content://call_log/calls";
Uri UriCalls = Uri.parse(strUriCalls);
//Cursor c = res.query(UriCalls, null, null, null, null);
if(null != resolver)
{

resolver.delete(UriCalls,CallLog.Calls.NUMBER +"=?",new String[]{ strNum}


}
}
catch(Exception e)
{
e.getMessage();
}
}

Note: Add your package file on top of the code when you will use it.

2. Add below user permissions in your Android manifest file


1
2

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

Add like below code in your projects manifest file.


1
2
3
4
5
6
7

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techblogon.updatecalllog"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

2/9

15/07/2015

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

android:minSdkVersion="8"
android:targetSdkVersion="16" />

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.techblogon.updatecalllog.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

Now it is time to just call AddNumToCallLog()/DeleteNumFromCallLog() functions of CallLogUtility Class,


where we want to add or delete numbers from/into Android calllog.

Add a number into call log in Android


Add below code snippets where you want to add a number in calllog just like below. In this example we will
add an outgoing call into the call log.
1
2
3
4
5
6
7

//Add number into calllog


longcallTimeInMiliSecond
= System.currentTimeMillis(); //time stamp
//CallLogUtility is the class where we have written our add/delete function
CallLogUtility utility = new CallLogUtility();
//number to add
String numberStr = "+918586887076";
utility.AddNumToCallLog(getBaseContext().getContentResolver(),numberStr, CallLog.Calls.OUTGOING_TY

Delete a number from call log in Android


Add below code snippets where you want to delete a number from calllog just like below. In this example we
will delete an number by querying in the calllog database if exist.
1
2
3
4

//if you want to delete any number from call log then follow below 2 lines of code
String numberStr = "+918554887076"; // delete this number from call log
CallLogUtility utility = new CallLogUtility();
utility.DeleteNumFromCallLog(getBaseContext().getContentResolver(), numberStr)

Update a number in call log in Android


//if you want to update any existing number in the callog then the better way to do is: First delete the number and
then insert a new number into the call log as describe above.
http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

3/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

I hope this small tutorial on Android Call Log Example Code (add, update, delete entries from call log) will
help you at its best.
Previous Page
Android Tutorial Home Page
Next Page

Post By SmrutiRanjan (57 Posts)

C ONNECT

Working @ Samsung as a Project Lead for Android


Smartphones. I have been blogging since 2008.
Previously I was writing articles for other bloggers, but
finally I have started my own blog-"Techblogon".I am also
an active contributor for the blog-"Gadgets n Gizmos
World". Job is my necessity, but blogging is my passion.
Website: Techblogon

android add entries in call log, android delete entries from call log, update call log in android

10 Responses to Android Call Log Example Code (add, update, delete numbers
from call log)
1.

polo ralph lauren pas cher says:


May 17, 2013 at 3:52 pm
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it
and I am looking forward to reading new articles. Keep up the good work.
Reply

2.

longchamp sale says:


May 22, 2013 at 5:33 am
Im often to running a blog and i actually appreciate your content.
Reply

3.

Shan Lin Htet says:


July 4, 2013 at 7:28 am
I want to create apk for my blog .
how to create apk with ADT bundle.
please post this article (How to create apk for web address)
Reply

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

4/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

SmrutiRanjan says:
July 6, 2013 at 6:58 pm
Dear Shan,
What kind of apk you want to create?
Reply
4.

Shan Lin Htet says:


July 4, 2013 at 7:30 am
I want to create apk for my blog
please post article for (How to create apk for website or blog )
Reply

5.

ashok says:
July 11, 2013 at 7:26 am
hi sir
please let me know ,during aunning my app i have an error like The method getBaseContext() is
undefined for the type CallLogUtility
why its happen, i followed whatever the steps you declared above
Reply
SmrutiRanjan says:
July 12, 2013 at 7:18 pm
getBaseContext();
This is only to collect the context of your app. You can use other way like passing it from where it
called
Reply

6.

maninder says:
July 22, 2013 at 10:44 pm
Hello,
Can you please point me to any open source code/example for taking a picture with voice command in
camera? It would seem that such an app, need to filter out all noise till it hear a specific word such as
shoot? Since google servers are responsible for converting voice commands to meaningful commands,
does it mean that all sounds captured by voice recognition would be sent to google?
Reply

7.

A.N says:

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

5/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

October 14, 2013 at 8:16 pm


Dear SmrutiRanjan
Thanks for your useful blog Actually I need source codes of phone and sms app which let me to work
on the UI part for my thesis .. do you have any suggestion for me ?
i am waiting for your kind reply
Best regards
Reply
8.

Sarah says:
November 16, 2013 at 5:01 am
I believe what you posted was actually very reasonable.
However, think on this, suppose you were to
write a killer headline? I aint saying your content is not solid., but
what if you added something to maybe get a persons attention?
I mean Android Call Log Example Code (add, update, delete numbers from call log)
| Techblogon is kinda boring. You could look at Yahoos home
page and note how they create article titles to
grab viewers to open the links. You might add a related video or a related picture or two to get readers
interested
about what youve written. In my opinion,
it would bring your website a little livelier.
Reply

Leave a Reply
Your email address will not be published. Required fields are marked *
Name *
Email *
Website
six 5 =

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

6/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym
title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del
datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" dataurl=""> <span class="" title="" data-url="">

Post Comment

Search

Techblogon
Follow

+1

+ 305
Like 1,859 people like this. Be the first of your friends.

Recommend on Google

Follow @techblogon

216 follow ers

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

7/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

Enter your Email Address...


Subscribe

RSS Feed

Google Plus

Archives
March 2015
July 2014
April 2014
October 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012

Categories
Android
Android Tutorial
Design Patterns
Displays
E-Commerce
Gadgets
Google
Internet
Mobile Phones
Softwares
Technologies
Tutorials
Windows

Pages
About us
Contact us
Privacy Policy
http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

8/9

15/07/2015

Android Call Log Example Code (add, update, delete numbers from call log) | Techblogon

Meta
Log in
Entries RSS
Comments RSS
WordPress.org

2015 Techblogon

http://techblogon.com/android-call-log-example-code-add-update-delete-numbers/

9/9

Anda mungkin juga menyukai