android – 获取调用日志时不推荐使用ManagedQuery()问题

我有一种方法,我试图获取手机的通话记录.但由于不推荐使用ManagedQuery(),我无法得到它.请帮助我如何修改它以满足我的需求.

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

不幸的是,编译器向我显示了一个问题:

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

因为不推荐使用managedQuery().

如何在不使用managedQuery()的情况下重写此方法?

解决方法:

您可以用它替换您的managedQuery:

Cursor managedCursor = getContentResolver().query(
                CallLog.Calls.CONTENT_URI, null, null, null, null);
上一篇:java – 关于Android API中的新方法和不推荐使用的方法


下一篇:即使我指定了api级别,Android也会弃用警告