简体   繁体   中英

not getting missed call value from call logs android

hey I am unable to get the call type == missed call and of current date only. Its can be achieved from Cursor query i have tried this but getting Calls type as missed call I am using this in onCreate method but not getting any value in logcat???? Here is my piece of code any help would be greatly appreciated......thanks in advance

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();

        }

try this:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM