2012-11-26 22 views
0

我想以編程方式清除我的Android手機中的所有通話記錄,並且我嘗試開發一個簡單的應用程序來完成此操作。但它不起作用,我希望有人能幫我檢查一下。如何清除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
Uri uri = Uri.parse("content://call_log/calls"); 

int d = getContentResolver().delete(uri, null, null); 

或檢查有多少刪除

​​
+0

這可能是更安全的使用靜態URI字符串(如你在第二個例子中所做的),而不是硬像在第一個例子中那樣編碼URI字符串。 'android.provider.CallLog.Calls.CONTENT_URI' – FoamyGuy

+0

是的,你是對的 – Talha

+0

我已經試過這 開放的URI = Uri.parse( 「內容:// call_log /調用」); getContentResolver()。delete(uri,null,null); 但它仍然不起作用 – user1782267