Reputation: 313
I would like to clear ALL the call history in my Android phone programmatically and I have tried developed a simple apps for doing so. But it is not working and I hope someone can just help me to check it.
public class ClearLogActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
Button clear;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
clear = (Button)findViewById(R.id.button1);
clear.setOnClickListener(this);
}
public void onClick(View view){
Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
while(cursor.moveToNext()){
getContentResolver().delete(CallLog.Calls.CONTENT_URI, null, null);
}
}
}
Upvotes: 0
Views: 1504
Reputation: 12717
Uri uri = Uri.parse("content://call_log/calls");
int d = getContentResolver().delete(uri, null, null);
or check how many deleted
int res = Call_logs.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);
if (res == 1) {
// Log delete
} else {
// Log not Delete
}
Upvotes: 4