Add, delete, modify, and query an android address book

Source: Internet
Author: User

*

* Get the current mobile phone number

*/

Public String getlocalnumber (){

Context context = getapplicationcontext ();

Telephonymanager tmanager = (telephonymanager) Context. getsystemservice (telephony_service );

String number = tmanager. getline1number ();

Return number;

}

// Delete call records

Private void deletecall ()

{

Getcontentresolver (). Delete (calllog. CILS. content_uri, calllog. CILS. Number + "=? ", New string [] {" 13078943473 "});

}

// Modify call records

Private void modifycall ()

{

Contentvalues content = new contentvalues ();

Content. Put (calllog. CILS. type, calllog. CILS. incoming_type );

Content. Put (calllog. CILS. Number, "13078945773 ");

Content. Put (calllog. CILS. Date, 123123123 );

Content. Put (calllog. CILS. New, "1"); // 0 read 1 not read

Getcontentresolver (). Update (calllog. CILS. content_uri, content, calllog. CILS. Number + "=? ", New string [] {" 13078943473 "});

}

// Add call records

Private void addcall ()

{

Contentvalues content = new contentvalues ();

Content. Put (calllog. CILS. type, calllog. CILS. incoming_type );

Content. Put (calllog. CILS. Number, "13078945773 ");

Content. Put (calllog. CILS. Date, 123123123 );

Content. Put (calllog. CILS. New, "1"); // 0 read 1 not read

Getcontentresolver (). insert (calllog. CILS. content_uri, content );

}

// Query call records

Private void getcall ()

{

Cursor cursor = getcontentresolver (). Query (calllog. CILS. content_uri,

Null, null, null, calllog. CILS. default_sort_order );

If (! Cursor. movetofirst ())

{

Log. I ("Call History", "No call history currently ");

Return;

}

Do

{

Cursor cur = getcontentresolver (). Query (calllog. CILS. content_uri, null );

Int numindex = cur. getcolumnindex (calllog. CILS. number );

Int typeindex = cur. getcolumnindex (calllog. CILS. type );

String phonenum = NULL;

Phonenum = cur. getstring (numindex );

Switch (typeindex)

{

Case 1: // dial in

Toast. maketext (context, "dial phone:" + phonenum, Toast. length_short). Show ();

Log. I ("call", "1:" + phonenum );

Break;

Case 2: // dial out

Toast. maketext (context, "outbound phone:" + phonenum, Toast. length_short). Show ();

Log. I ("call", "2:" + phonenum );

Break;

Case 3: // not answered

Toast. maketext (context, "missed phone:" + phonenum, Toast. length_short). Show ();

Log. I ("call", "3:" + phonenum );

Break;

Default:

Log. I ("call", "defalut ");

Break;

}

/*

New String [] {calllog. CILS... commondatakinds. Nickname. name },

Contactscontract. commondatakinds. Nickname. contact_id + "=" + contactid + "and" +

Contactscontract. Data. mimetype + "= '" + contactscontract. commondatakinds. Nickname. content_item_type + "'",

*/

} While (cursor. movetonext ());

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.