*
* 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 ());
}