使用sms日志在android版本4.0.4中的相同位置调用日志

时间:2013-10-08 07:33:29

标签: java android

我正在创建以这种方式读取呼叫记录的应用程序:

 Uri uriCallsURI = Uri.parse("content://call_log/calls");
 Cursor cur = mainActivity.getContentResolver().query(uriCallsURI, null, null, null, "_id");

一切都在使用android 2.3.6,但android 4.0.4也将SMS显示为通话记录。 如何防止这种情况发生?

2 个答案:

答案 0 :(得分:0)

不要硬编码字符串。尝试编写如下代码:

Cursor cur = null;
        try {
            cur = getContentResolver().query(CallLog.Calls.CONTENT_URI,
                    new String[] { BaseColumns._ID, CallLog.Calls.NUMBER },
                    null, null, "_id");

            if (cur != null && cur.moveToFirst()) {
                do {
                    Log.i("call", "id = " + cur.getString(0));
                    Log.i("call", "number = " + cur.getString(1));
                    Log.i("call", "..................................");
                } while (cur.moveToNext());
            }
        } finally {
            if (cur != null) {
                cur.close();
            }
        }

答案 1 :(得分:0)

yushulx,问题在其他地方。三星在通话记录中有列日志类型。我找到了答案 Samsung device returns text messages when querying for call-log

我修改了你的代码,现在我只获得了使用android 4.0.4的三星手机上的通话记录。

Cursor cur = null;
try {

    cur = getContentResolver().query(CallLog.Calls.CONTENT_URI,
            new String[] { BaseColumns._ID, CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME, 
            CallLog.Calls.DURATION, CallLog.Calls.DATE, CallLog.Calls.TYPE,  CallLog.Calls.NEW},
            "logtype=100 OR logtype=500", null, "_id");

    displayLogs(cur);

} catch(SQLiteException e){

    cur = getContentResolver().query(CallLog.Calls.CONTENT_URI,
            new String[] { BaseColumns._ID, CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME, 
            CallLog.Calls.DURATION, CallLog.Calls.DATE, CallLog.Calls.TYPE,  CallLog.Calls.NEW},
            null, null, "_id");

     displayLogs(cur);

} finally {
    if (cur != null) {
        cur.close();
    }
}