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"相关的通话记录。

相关内容

热门资讯

2分钟大纲!wepoker怎么... 2分钟大纲!wepoker怎么发冤家牌(透视)一贯是真的有辅助神器(哔哩哔哩)1、wepoker怎么...
第十分钟技法!wepoker私... 第十分钟技法!wepoker私人局怎么玩(透视)竟然真的是有辅助辅助(哔哩哔哩)1)wepoker私...
第十分钟方式!哈糖大菠萝开挂(... 第十分钟方式!哈糖大菠萝开挂(透视)其实存在有辅助工具(哔哩哔哩)1、实时哈糖大菠萝开挂透视辅助更新...
三分钟机巧!wepoker科技... 三分钟机巧!wepoker科技辅助器(透视)果然有辅助安装(哔哩哔哩)1、上手简单,内置详细流程视频...
8分钟技法!wepoker辅助... 8分钟技法!wepoker辅助插件功能(透视)切实有辅助透视(哔哩哔哩)wepoker辅助插件功能辅...
第4分钟手段!wepoker好... 第4分钟手段!wepoker好友局透视(透视)都是有辅助开挂(哔哩哔哩)1、下载好wepoker好友...
2分钟要领!wpk透视辅助方法... 2分钟要领!wpk透视辅助方法(透视)一直有辅助教程(哔哩哔哩)1、金币登录送、破产送、升级送、活动...
第一分钟模块!wepoker透... 第一分钟模块!wepoker透视底牌脚本(透视)切实真的是有辅助辅助(哔哩哔哩)一、wepoker透...
第9分钟绝活儿!红龙poker... 第9分钟绝活儿!红龙poker作必弊指令(透视)竟然存在有辅助工具(哔哩哔哩)一、红龙poker作必...
第3分钟办法!哈糖大菠萝破解器... 第3分钟办法!哈糖大菠萝破解器(透视)总是是有辅助教程(哔哩哔哩)1、进入到哈糖大菠萝破解器是否有挂...