我想以编程方式清除Android手机中的所有通话记录,并尝试开发一个简单的应用程序。但它不起作用,我希望有人可以帮我检查一下。
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);
}
}
}
答案 0 :(得分:4)
Uri uri = Uri.parse("content://call_log/calls");
int d = getContentResolver().delete(uri, null, null);
或检查删除了多少
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
}