您好我是Android的新手。请帮我在android中使用内容解析器获取特定号码的通话记录?下面的代码给出了所有数字的日志,但我想得到一个特定数字的日志。提前谢谢。
StringBuffer sb = new StringBuffer();
String order = android.provider.CallLog.Calls.DATE+" DESC";
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, order);
int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
while(cursor.moveToNext()){
String phNum = cursor.getString(number);
int callType = Integer.parseInt(cursor.getString(type));
switch(callType){
case CallLog.Calls.OUTGOING_TYPE:
break;
}
sb.append("Contact:"+phNum);
}
答案 0 :(得分:0)
StringBuffer sb = new StringBuffer();
String order = android.provider.CallLog.Calls.DATE+" DESC";
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, order);
int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
while(cursor.moveToNext()){
String phNum = cursor.getString(number);
if (phNum.equalIgnorCase("Your Number")
{
//here you get particular no call
}
}
答案 1 :(得分:0)
不是我尝过的东西,但你需要使用“选择”#39;用于指定电话号码的query(...)
方法的参数。
这样的事可能有用......
String numberToSearch = "01234567890";
String order = android.provider.CallLog.Calls.DATE + " DESC";
// The third parameter is for the 'selection'
Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, "NUMBER=" + numberToSearch, null, order);
if(cursor != null && cursor.count() > 0) {
// If you got this far then you have at least one record
// for the number you searched for
int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
while(cursor.moveToNext()) {
String phNum = cursor.getString(number);
int callType = Integer.parseInt(cursor.getString(type));
// Do what you need to do with phNum and callType
}
}