2012-01-24 34 views
1

我正在使用CallLog,并将我的一个变量设置为用户拨打的联系人的CACHED_NAME。这可以正常工作,但是如果用户拨打的号码不在其联系人中,我希望将该变量设置为NUMBER的值。出于某种原因,当我这样做时,我得到的结果是单个数字的整数,例如“1”或“7”。这里是我的代码:CallLog没有给出正确的NUMBER值(拨打的号码)

Uri allCalls = Uri.parse("content://call_log/calls"); 
    String sortOrder = CallLog.Calls.DATE; 
    Cursor c = managedQuery(allCalls, null, null, null, sortOrder); 

    while (c.moveToNext()) { 

     int callType = Integer.parseInt(c.getString(c 
       .getColumnIndex(CallLog.Calls.TYPE))); 
     long date = c.getLong(c.getColumnIndex(Calls.DATE)); 
     String col1; 

     if (callType == CallLog.Calls.OUTGOING_TYPE 
       && date > resetDate) { 

       col1 = c.getString(c.getColumnIndex(Calls.CACHED_NAME)); 
       // if there is no cached name, get the number 
       if (col1 == null) { 
        col1 = String.valueOf(c.getLong(c 
          .getColumnIndex(Calls.NUMBER))); 
       } 

上午我说得对,为NUMBER的值应该是电话号码,用户拨?我知道除了最后一行,我将col1设置为数字值以外,所有内容都是正确的。有任何想法吗?

回答

1

您正在使用getLong的电话号码时,你应该使用getString

col1 = c.getString(c.getColumnIndex(Calls.CACHED_NAME)); 
// if there is no cached name, get the number 
if (col1 == null) { 
    col1 = String.valueOf(c.getString(c 
     .getColumnIndex(Calls.NUMBER))); 
} 
+0

什么是新手的错误!完全错过了,最终做了不同的事情,但谢谢你的答案。 –