以下android代码有什么问题?

时间:2016-02-11 20:52:32

标签: android

我正在尝试将通话类型与“错过”#39;调用

我正在使用CallLog.Calls.TYPE来执行此操作,但我在应用内部无法获得所需的输出。

以下是代码。

 if (Integer.parseInt(CallLog.Calls.TYPE)==CallLog.Calls.MISSED_TYPE) {
     dir = "MISSED";
     sb.append("\nName: " + namee + "\nPhone Number:  " + phNumber + " \nCall Type:  " + dir + " \nCall Date:   " + callDayTime
                            + " \nCall duration in sec :   " + callDuration);

 }

1 个答案:

答案 0 :(得分:3)

您没有正确比较。你正在比较常数。您需要与使用Cursor提取的ContentResolver内的值进行比较

如果您的查询结果为cursor,请执行此操作

String callType = cursor.getString(cursor.getColumnIndex(android.provider.CallLog.Calls.TYPE));

然后

if(Integer.parseInt(callType) == CallLog.Calls.MISSED_TYPE ){
    dir = "MISSED";
    sb.append("\nName: " + namee + "\nPhone Number:  " + phNumber + " \nCall Type:  " + dir + " \nCall Date:   " + callDayTime
                        + " \nCall duration in sec :   " + callDuration);
}