简体   繁体   中英

How to get a number from the Call log and use it to save to an Object - Android

From the android device i do need to select a number from the CAll Log and use it to set in my own object . I am looking at CallLog.Calls but only outgoing is provided?

I use the following to query the Call Log.

    final String[] projection = null;
    final String selection = null;
    final String[] selectionArgs = null;
    final String sortOrder = "DATE DESC";
    Cursor cursor = _context.getContentResolver().query(
            Uri.parse("content://call_log/calls"),
            projection,
            selection,
            selectionArgs,
            sortOrder);
    if (cursor != null) {
        //Loop through the call log.
        while (cursor.moveToNext()) { 
            //Common Call Log Items
            String callNumber = cursor.getString(cursor.getColumnIndex(
                                    android.provider.CallLog.Calls.NUMBER));
            String callDate = cursor.getString(cursor.getColumnIndex(
                                    android.provider.CallLog.Calls.DATE));
            String callType = cursor.getString(cursor.getColumnIndex(
                                    android.provider.CallLog.Calls.TYPE));
            String isCallNew = cursor.getString(cursor.getColumnIndex(
                                    android.provider.CallLog.Calls.NEW));
            //DO YOUR WORK HERE...
        }
    }

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM