getting the call logs of incoming and outgoing calls in android programmatically

前端 未结 5 1846
执笔经年
执笔经年 2021-02-02 04:34

I am making an app in which I want to get the call logs of all incoming, outgoing and missed calls. How can I do that?

5条回答
  •  别跟我提以往
    2021-02-02 05:21

     private void getLastNumber() {
    
           //this help you to get recent call
            Uri contacts = CallLog.Calls.CONTENT_URI;
            Cursor managedCursor = context.getContentResolver().query(contacts, null, null, 
                           null, android.provider.CallLog.Calls.DATE + " DESC limit 1;");
            int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
            int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
            int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
            int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
    
            StringBuffer sb = new StringBuffer();
            managedCursor.moveToNext();
            String phNumber = managedCursor.getString(number);
            String callType = managedCursor.getString(type);
            String callDate = managedCursor.getString(date);
            String callDayTime = new Date(Long.valueOf(callDate)).toString();
            int callDuration = managedCursor.getInt(duration);
            managedCursor.close();
    
            int dircode = Integer.parseInt(callType);
           sb.append("Phone Number:--- " + phNumber + " ,Call Date:--- " + callDayTime + " ,Call duration in sec :--- " + callDuration);
            sb.append("\n----------------------------------");
            Log.d("calllogs", "getLastNumber: "+"Phone Number:--- " + phNumber + " ,Call Date:--- " + callDayTime + " ,Call duration in sec :--- " + callDuration);
        }
    

提交回复
热议问题