How Can I Read Call Log?


#1

Hello, I’m new to ionic and cordova as well. I’m trying to get the call logs / call history.

I tried searching in Google, but the only plugin I find is https://github.com/dalyc/Cordova-CallLog-Plugin which is not supported anymore. Even the Girhub page doesn’t exists anymore https://github.com/uriva/CallLogPlugin.

Other search results are not of much use I believe. Can you please help me out?


#2

hi…have you find solution for this?? i need same


#3

Unfortunately No :frowning2:

I developed my requirement in Native code. You can do so in Native code but it seems there’s still no support for such in Cordova.


#4

i want to add this in my ionic app Please can you share your code??


#5

Hi, As I already said, I couldn’t find anything in Cordova and thus I developed the whole App in Native Android.

Here’s a below snippet of how I did it in Native

    private List<ReadCallLog> readCallLogs()
    {
        List<ReadCallLog> readCallLogs = new ArrayList<ReadCallLog>();
        Cursor managedCursor = null;

        try{
            managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
            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);

            while (managedCursor.moveToNext()) {
                ReadCallLog readCallLog = new ReadCallLog();

                String phNumber = managedCursor.getString(number);
                String callType = managedCursor.getString(type);
                String callDate = managedCursor.getString(date);
                Date callDayTime = new Date(Long.valueOf(callDate));
                String callDuration = managedCursor.getString(duration);
                String dir = null;
                int dircode = Integer.parseInt(callType);
                switch (dircode) {
                    case CallLog.Calls.OUTGOING_TYPE:
                        dir = "OUTGOING";
                        break;
                    case CallLog.Calls.INCOMING_TYPE:
                        dir = "INCOMING";
                        break;
                    case CallLog.Calls.MISSED_TYPE:
                        dir = "MISSED";
                        break;
                }

                readCallLog.PhoneNumber = phNumber;
                readCallLog.CallType = dir;
                readCallLog.CallDate = callDayTime;
                readCallLog.CallDuration = callDuration;

                readCallLogs.add(readCallLog);
            }

        } catch(SecurityException ex) {
            Log.d(TAG, "Read Call Log : Permission Refused");
        } finally {
            if(managedCursor != null)
            {
                if(!managedCursor.isClosed())
                    managedCursor.close();
            }

            PostCallLogData(readCallLogs);

            return readCallLogs;
        }
    }