Question

I am developing a program in which I need to get all calls(Recived, missed, dailed) details of my phone and want to save in database which is created by me.. So I need to consult 2 things.

1- Is it possible to do it as I want?

2- If it is,then how?

Was it helpful?

Solution 2

Ya, it is possible. Refer the below links. It will give an idea.

http://android2011dev.blogspot.in/2011/08/get-android-phone-call-historylog.html

How do I access call log for android?

http://developer.android.com/reference/android/provider/CallLog.Calls.html

And also after retrieving all the details of your need, you can insert them into database according to your needs.

OTHER TIPS

First you need to give the permission to read call logs from the device.

<uses-permission android:name="android.permission.READ_CONTACTS" />

Now use this method to get the recent call logs getCallDetails()

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 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();
    call.setText(sb);
}

Hope it will hemp you out for your need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top