Wednesday, December 14, 2011

Removes the specified Call row permently from the CallLog in ANDROID

AIM : To removes the specified Call row from the Call Log in ANDROID
Solution:
The following method does the function. It requires "CALL LOG ID" of a particular callLog row.

        String strUriCalls = "content://call_log/calls";
        Uri UriCalls = Uri.parse(strUriCalls);
        String queryString = Calls._ID + "='" + rowID + "'";
        Log.v("Number", queryString);
        int i = getContentResolver().delete(UriCalls, queryString, null);
        Log.v("Number", "Deleted Rows:" + i);
We Can read the CALL LOG ID of  particular row(call) in android call hisory.
By using the following lines.


Cursor c = contentResolver.query(Uri.parse("content://call_log/calls"),null,null, null,android.provider.CallLog.Calls.DEFAULT_SORT_ORDER);
        // Retrieve the column-indixes of phoneNumber, date and calltype
        int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
        int dateColumn = c.getColumnIndex(android.provider.CallLog.Calls.DATE);
        // type can be: Incoming, Outgoing or Missed
        int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
        int durationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);
       
        // Will hold the calls, available to the cursor
       
                // Loop through all entries the cursor provides to us.
        if(c.moveToFirst()){
            do{
                String callerPhoneNumber = c.getString(numberColumn);
                Long callDate = c.getLong(dateColumn);
                int callType = c.getInt(typeColumn);
                int duration = c.getInt(durationColumn);
               
                 switch(callType){
                    case android.provider.CallLog.Calls.INCOMING_TYPE:
           
           break;
                    case android.provider.CallLog.Calls.MISSED_TYPE:
                       
                        break;
                    case android.provider.CallLog.Calls.OUTGOING_TYPE:

                        break;
                }
           
                String cName=c.getString(c.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
                String cId=c.getString(c.getColumnIndex(android.provider.CallLog.Calls._ID));
                                       }while(c.moveToNext());
        }
   
SImilarly,you can read all properties of a calllog programatically.
It works on all above 2.2 + versions.

No comments:

Post a Comment

Android Developers Blog

Ram's shared items