I would like to receive the call log. For example the number of calls made by the user, number of minutes called, etc.
How do I achieve this in android?
How to find Call Logs on your phone. To access your call history (i.e. a list of all of your call logs on your device), simply open your device's phone app which looks like a telephone and tap Log or Recents. You'll see a list of all incoming, outgoing calls and missed calls.
Step 1. From the home screen, choose Apps or swipe up to access your Apps and then tap Phone. Step 2. Tap Recents to see your call history, in some Android phones it may be called Log, Call History, or something similar.
It's stored in /data/data/com. android. providers. contacts/databases/calllog.
Step 1: Connect the Android phone to your computer using a USB cord. Step 2: Allow USB Debugging on your Android phone. Step 3: Select the file type you need to recover - Call History. Step 4: Start to scan and find the deleted call logs on your Android phone.
This is for accessing phone call history:
As of Jellybean (4.1) you need the following permission:<uses-permission android:name="android.permission.READ_CALL_LOG" />
Code:
Uri allCalls = Uri.parse("content://call_log/calls"); Cursor c = managedQuery(allCalls, null, null, null, null); String num= c.getString(c.getColumnIndex(CallLog.Calls.NUMBER));// for number String name= c.getString(c.getColumnIndex(CallLog.Calls.CACHED_NAME));// for name String duration = c.getString(c.getColumnIndex(CallLog.Calls.DURATION));// for duration int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going.
This is method used to get the Call log. Just put this method in you class and get the List of the Call Log.
Check out this
private String getCallDetails() { StringBuffer sb = new StringBuffer(); Cursor managedCursor = managedQuery(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); sb.append("Call Details :"); while (managedCursor.moveToNext()) { 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; } sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration); sb.append("\n----------------------------------"); } managedCursor.close(); return sb.toString(); }
the output looks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With