Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated ManagedQuery() issue in getting call logs

I have a method in which i am trying to get call logs of a phone. but because of deprecated ManagedQuery() i am not able to get that. Please help how can i modify that to meet my needs.

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);
    }

Unfortunately the compiler show me a problem on:

Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,       null, null, null);

Because managedQuery() is deprecated.

How could I rewrite this method without using managedQuery()?

like image 531
Sangeeta Avatar asked Dec 17 '15 07:12

Sangeeta


2 Answers

You can replace your managedQuery with it :

Cursor managedCursor = getContentResolver().query(
                CallLog.Calls.CONTENT_URI, null, null, null, null);
like image 182
Harsh Parikh Avatar answered Nov 05 '22 18:11

Harsh Parikh


I found my answer here..

LoaderManager.LoaderCallbacks

Thanks everyone for the help!!!

like image 2
Sangeeta Avatar answered Nov 05 '22 19:11

Sangeeta