0

我想以编程方式清除我的 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);
    }
}

}

4

1 回答 1

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

        }
于 2012-11-26T15:23:25.130 回答