Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

calllog - Android: get call history of contact

i am using this code the get to the contact info of a contact (i am using it also - with a few modifications - to call, send sms or email the contact). I wonder if there is a way to show the call history of a certain contact:

String name3 is the contact name.

     contactinfobtn.setOnClickListener(new View.OnClickListener() 
     {
        public void onClick(View v) 
        { 
            ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

            if (cur.getCount() > 0) 
            {

                while (cur.moveToNext()) {
                id_contact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                name_contact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    if (name_contact.equals(name3))
                    {
                    Cursor pCur = cr.query(
                    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id_contact}, null);
                       id_contact2 = id_contact;

                        while (pCur.moveToNext()){
                        } 
                    pCur.close();
                    }
                }
                Intent intent_contacts = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/" + id_contact2));
                startActivity(intent_contacts);
            }
        }
     });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a class called CallLog.Calls that contains the CONTENT_URI to query for call history.

Here's an example listing the phone numbers in the call log:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.main);

    String[] projection = new String[] {
        CallLog.Calls._ID, CallLog.Calls.NUMBER};
    Cursor query = this.managedQuery(
        CallLog.Calls.CONTENT_URI, projection, null, null, null);

    ListAdapter adapter = new SimpleCursorAdapter(
        this, android.R.layout.simple_list_item_1, query,
        new String[] {CallLog.Calls.NUMBER},
        new int[] {android.R.id.text1});
    this.setListAdapter(adapter);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...