没有从呼叫日志android中错过呼叫值

时间:2014-02-28 06:13:39

标签: android calllog

嘿,我无法获得呼叫类型==未接来电和当前日期。 它可以通过Cursor查询实现我已经尝试了这个但是将Calls类型作为未接来电 我在onCreate方法中使用它但没有在logcat中获取任何值? 这是我的一段代码,任何帮助将不胜感激......提前感谢

String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;
    int missedtype=CallLog.Calls.MISSED_TYPE;
    String missed=Integer.toString(missedtype);

    String timestamp = String.valueOf(getTodayTimestamp());

    Cursor cursor = this.getContentResolver()
            .query(CallLog.Calls.CONTENT_URI,
                    new String[] { CallLog.Calls.DATE, CallLog.Calls.TYPE,
                            CallLog.Calls.DURATION, CallLog.Calls.NUMBER,
                            CallLog.Calls._ID },
                    CallLog.Calls.DATE + ">?" + " and "
                            + CallLog.Calls.TYPE + "=?",
                    new String[] { timestamp, String.valueOf(CallLog.Calls.MISSED_TYPE) },
                    CallLog.Calls.DATE);
    //Cursor managedCursor = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.DATE + ">= ?", new String[]{timestamp}, null);
     //Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI,   null, where , null, CallLog.Calls.DATE+ " >= ?");

        int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
        int date = cursor.getColumnIndex(CallLog.Calls.DATE);
        int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);    
        {
        while (cursor.moveToNext()) {
            String LogphNumber = cursor.getString(number);  
            String callType = cursor.getString(type);
            String callDate = cursor.getString(date);              
            Date callDayTime = new Date(Long.valueOf(callDate));
            String callDuration = cursor.getString(duration);
    {

        if(cursor.getCount()>1){

           System.out.println("Total Logs::>>>>>>>>> "+cursor.getCount());
           System.out.println("\nPhoneNo:----"+LogphNumber);            
           System.out.println("\nCallDate: "+callDayTime);
           System.out.println("\nCallDuration in Seconds :"+callDuration);
           System.out.println("\n-----------------------");

       }else if(cursor.getCount()==0){
           System.out.println("No Missed calls");
       }
    }
        }cursor.close();

        }

1 个答案:

答案 0 :(得分:0)

试试这个:

String timestamp = String.valueOf(getTodayTimestamp());
Cursor cursor = this.getContentResolver()
            .query(CallLog.Calls.CONTENT_URI,
                    new String[] { CallLog.Calls.DATE, CallLog.Calls.TYPE,
                            CallLog.Calls.DURATION, CallLog.Calls.NUMBER,
                            CallLog.Calls._ID },
                    CallLog.Calls.DATE + ">?" + " and "
                            + CallLog.Calls.TYPE + "=?",
                    new String[] { timestamp, String.valueOf(CallLog.Calls.MISSED_TYPE) },
                    CallLog.Calls.DATE);