获得某个电话的通话记录次数times

 public static int getPhoneRecordTimes(Context mContext,String phoneNumber){
        Cursor cursor = mContext.getContentResolver().query(CallLog.Calls.CONTENT_URI,
                null, null, null, null);
        int times = 0;
        if(cursor.moveToFirst()){
            do{
                //CallLog calls =new CallLog();
                //呼叫类型
                String type;
                switch (Integer.parseInt(cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE)))) {
                    case CallLog.Calls.INCOMING_TYPE:
                        type = "呼入";
                        break;
                    case CallLog.Calls.OUTGOING_TYPE:
                        //如果传过来的电话号码与检测系统中通话记录相同,则times+1
                        if(phoneNumber.equals(cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)))){
                            times = times + 1;
                        }
                        type = "呼出";
                        break;
                    case CallLog.Calls.MISSED_TYPE:
                        type = "未接";
                        break;
                    default:
                        type = "挂断";
                        break;
                }
            }while(cursor.moveToNext());
       
            SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
            Date date = new Date(Long.parseLong(cursor.getString(cursor.getColumnIndexOrThrow(Calls.DATE))));
            //呼叫时间 
            String time = sfd.format(date); 
            //联系人 
            String name = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME)); 
            //通话时间,单位:s 
            String duration = cursor.getString(cursor.getColumnIndexOrThrow(Calls.DURATION)); 
        }
        return times;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值