Retrieve phone call history

Source: Internet
Author: User
Retrieve phone call history
1. Recently I want to learn about how to get the phone history call records. I wrote the following method to use log to generate qualified call records, including numbers, phone connection times, call IDs, and call times:
Private cursor getphonetracking (string number ){
// Obtain a set that meets the query conditions.
Cursor cursor = getcontentresolver (). Query (calllog. CILS. content_uri,
New String [] {"Number", "_ id", "date", "type", "duration "},
"Number =" + number, // select a qualified record. For example, you can write null, "_ id =" + id
Null, calllog. CILS. default_sort_order );
Startmanagingcursor (cursor );
If (cursor. movetofirst ()){
String num = "", _ id = "", time = "", duration = "";
Simpledateformat SDF = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
Do {
// Call number
Num = cursor. getstring (cursor
. Getcolumnindex (calllog. CILS. Number ));
// Call ID
_ Id = cursor
. Getstring (cursor. getcolumnindex (calllog. CILS. _ id ));
// Call time
Time = cursor. getstring (cursor
. Getcolumnindex (calllog. CILS. Date ));
Long date = long. parselong (time );
// Format the date
Time = SDF. Format (date );
// Call time
Duration = cursor. getstring (cursor
. Getcolumnindex (calllog. CILS. duration ));
// Log the call record information
Log. D ("============= number ===============", num );
Log. D ("=============_ ID ================", _ id );
Log. D ("=============== time ===============", time );
Log. D ("============== duration ==============", duration );
Log. D ("========================================",
"================================= ");
} While (cursor. movetonext ());
}
Return cursor;
}
2. Call
For example, if you want to select a call record with the phone number 10086, you can use it like this (the call record with the phone number 10086 should be available ):
Cursor c = getphonetracking ("10086"); // call
// Display in list
Startmanagingcursor (C );
Simplecursoradapter adapter = new simplecursoradapter (this,
R. layout. callinfo, C, new string [] {"Number", "_ id", "date ",
"Type", "duration"}, new int [] {R. Id. textnumber,
R. Id. textname, R. Id. textduration, R. Id. texttype,
R. Id. duration });
Setlistadapter (adapter );

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.