Android:如何搜索特定号码的通话记录
创始人
2024-10-13 16:30:30
0

要搜索特定号码的通话记录,可以使用以下代码示例:

public ArrayList searchCallLogs(Context context, String phoneNumber) {
    ArrayList callLogs = new ArrayList<>();
    
    // 获取通话记录的URI
    Uri callUri = CallLog.Calls.CONTENT_URI;
    
    // 定义要查询的字段
    String[] projection = new String[]{
            CallLog.Calls.NUMBER,
            CallLog.Calls.DATE,
            CallLog.Calls.DURATION,
            CallLog.Calls.TYPE
    };
    
    // 设置查询条件
    String selection = CallLog.Calls.NUMBER + " = ?";
    String[] selectionArgs = new String[]{ phoneNumber };
    
    // 查询通话记录
    Cursor cursor = context.getContentResolver().query(
            callUri,
            projection,
            selection,
            selectionArgs,
            CallLog.Calls.DATE + " DESC"
    );
    
    // 遍历查询结果
    if (cursor != null && cursor.moveToFirst()) {
        do {
            String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
            String date = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DATE));
            String duration = cursor.getString(cursor.getColumnIndex(CallLog.Calls.DURATION));
            String type = cursor.getString(cursor.getColumnIndex(CallLog.Calls.TYPE));
            
            // 将通话记录添加到列表中
            callLogs.add("Number: " + number + ", Date: " + date + ", Duration: " + duration + ", Type: " + type);
        } while (cursor.moveToNext());
        
        cursor.close();
    }
    
    return callLogs;
}

要使用上述代码示例,可以在Android应用的活动或片段中调用searchCallLogs方法,并传入要搜索的电话号码。该方法将返回一个包含匹配的通话记录的字符串列表。请确保在使用此代码之前已经获取了通话记录的读取权限。

示例用法:

ArrayList callLogs = searchCallLogs(getApplicationContext(), "9876543210");

for (String callLog : callLogs) {
    Log.d("Call Log", callLog);
}

这将打印出与电话号码"9876543210"相关的通话记录。

相关内容

热门资讯

安装程序教程!aapoker脚... 安装程序教程!aapoker脚本,aapoker怎么控制牌,必胜教程(有挂神器)是一款可以让一直输的...
实测交流!聚星ai辅助工具下载... 实测交流!聚星ai辅助工具下载,wpk安卓下载辅助,科技教程(有挂透视)1、点击下载安装,微扑克wp...
必看攻略!wepoker透视a... 必看攻略!wepoker透视app下载,wpk模拟器,2025新版教程(有挂透明);玩家必备必赢加哟...
总算清楚!hhpoker到底可... 总算清楚!hhpoker到底可以作弊码,pokemmo手机脚本辅助器,2025新版教程(有挂方法);...
记者爆料!约局吧能不能开挂,w... 此外,数据分析德州(约局吧能不能开挂)辅助神器app还具备辅助透视行为开挂功能,通过对客户约局吧能不...
技术分享!wepoker辅助器... 技术分享!wepoker辅助器官方,sohoo辅助,软件教程(有挂技巧)准备好在wepoker辅助器...
信息共享!cloudpoker... 这是一款非常优秀的cloudpoker怎么开挂 ia辅助检测软件,能够让你了解到cloudpoker...
推荐十款!wepoker透视脚... 推荐十款!wepoker透视脚本视频,hhpoker买挂,安装教程(有挂神器);科技安装教程;136...
科普攻略!aapoker辅助怎... 科普攻略!aapoker辅助怎么用,hhpoker有后台操作吗,安装教程(有挂技巧)1、点击下载安装...
玩家必看教程!竞技联盟破解版最... 玩家必看教程!竞技联盟破解版最新版,云扑克有透视吗,技巧教程(有挂辅助)这是由厦门游乐互动科技有限公...