Get Contact by Phone number on Android

前端 未结 3 2032
刺人心
刺人心 2020-12-20 04:50

I know how I can get all contacts in Android , and how to get their phone number.

What I cant seem to figure out is how to get a contact by phone number...

T

3条回答
  •  一生所求
    2020-12-20 05:20

    Use this kind of code:

    public void logCallLog(String number)
    {
        long dialed;
        String columns[]=new String[] {
                CallLog.Calls._ID,
                CallLog.Calls.NUMBER,
                CallLog.Calls.DATE,
                CallLog.Calls.DURATION,
                CallLog.Calls.TYPE};
        String args[]=new String[1];
        args[0]=number;
        Cursor c;
        c = this.managedQuery(Uri.parse("content://call_log/calls"),
                columns, CallLog.Calls.NUMBER+"=?", args, "Calls._ID DESC"); //last record first
        while (c.moveToNext())
        {
            dialed=c.getLong(c.getColumnIndex(CallLog.Calls.DATE));
            if(Me.DEBUG)
                Log.v("CallLog", "Call to number: "+number+", registered at: "+new Date(dialed).toString());
        }
    }
    

提交回复
热议问题