我想单独获取特定的通话类型,并将其从android的通话记录中删除。
while (cursor.moveToNext()) {
String queryString1= "CallType=’" + CallLog.Calls.MISSED_TYPE + "‘";
Log.v("CallType", queryString1);
if(CallLog.Calls.TYPE.equals("missed")) {
sb.append("Number "+CallLog.Calls.NUMBER+"\nName "+CallLog.Calls.CACHED_NAME);
}
}
getContentResolver().delete(UriCalls, CallLog.Calls.MISSED_TYPE, null);
这是我为未接来电尝试的代码,因为Missed_type为int,我收到一个错误“ ContentResolver类型的delete(Uri,String,String [])方法不适用于参数(Uri,int,null )”
给我一些提示,以从日志中删除特定的呼叫类型
最佳答案
您可以使用以下代码获取未接来电提醒
final String[] projection = null;
final String selection = null;
final String[] selectionArgs = null;
final String sortOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor cursor = null;
try{
cursor = context.getContentResolver().query(
Uri.parse("content://call_log/calls"),
projection,
selection,
selectionArgs,
sortOrder);
while (cursor.moveToNext()) {
String callLogID = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls._ID));
String callNumber = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
String callDate = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.DATE));
String callType = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE));
String isCallNew = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.NEW));
if(Integer.parseInt(callType) == MISSED_CALL_TYPE && Integer.parseInt(isCallNew) > 0){
if (_debug) Log.v("Missed Call Found: " + callNumber);
}
}
} catch(Exception ex){
if (_debug) Log.e("ERROR: " + ex.toString());
}finally{
cursor.close();
}
您也可以使用此链接http://android2011dev.blogspot.in/2011/08/get-android-phone-call-historylog.html
<uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
在androidmanifest.xml中授予上述权限
使用以下链接删除未接来电列表,您只需要传递您从上述代码中获得的号码
http://www.mobisoftinfotech.com/blog/android/androidcalllogdeletion/