How to filter the name of the android call history

0

Hi, I would like to filter the call history that I am getting by android, that is, show only those of one of my contacts, I am not sure if this can be done. Here is the function that works for me without problem:

private void getCallDetails() {

    Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,  
    null, null, null);

    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int name_count = 
    managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);

    while (managedCursor.moveToNext()) {
        name = managedCursor.getString(name_count);
        phNumber = managedCursor.getString(number);


            model.add(new Item_llamadas(name, phNumber));



    } //managedCursor.close(); textView.setText(sb); } }
    listapersonalizada.setAdapter(new Adapter_llamadas(this, model));

}
    
asked by flo 03.10.2017 в 17:44
source

1 answer

0

You can modify your method to define the name of the contact and this will make the save only when the name matches:

   //*Si coincide el nombre del contacto con el registro, guarda el elemento.
            if(nombreContacto.equals(name)){ 

                model.add(new Item_llamadas(name, phNumber));

            }

this would be the complete code, as an example getCallDetails("flo"); to get all calls from "flo":

private void getCallDetails(String nombreContacto) {

    Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,  
    null, null, null);

    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int name_count = 
    managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);

    while (managedCursor.moveToNext()) {
        name = managedCursor.getString(name_count);
        phNumber = managedCursor.getString(number);

        //*Si coincide el nombre del contacto con el registro, guarda el elemento.
        if(nombreContacto.equals(name)){ 

            model.add(new Item_llamadas(name, phNumber));

        }


    } //managedCursor.close(); textView.setText(sb); } }
    listapersonalizada.setAdapter(new Adapter_llamadas(this, model));

}
    
answered by 03.10.2017 / 19:16
source