Created
November 12, 2014 15:38
-
-
Save msomu/24f5a66bf98f26e0be02 to your computer and use it in GitHub Desktop.
Read Call Logs in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void 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 Log :"); | |
| 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(); | |
| textView.setText(sb); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <uses-permission android:name="android.permission.READ_CALL_LOG"/> |
You need to have your privacy policy done right . and you must ask for the user permission manually to access the call log.
Hy there
I have used the same thing but i am not getting all the longs but the few ones
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
READ_CALL_LOG permission not accept to play store please help