如何显示最近的通话记录

时间:2014-03-24 07:52:18

标签: android

我是android编程的新手。我希望最近的通话记录数据不是我写这段代码的整个历史记录。它显示最新通话记录的所有记录。 请帮我。请告诉我使用什么或如何获取最新的通话数据这是我的代码

public class MainActivity extends Activity {
    TextView call;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         call =(TextView) findViewById(R.id.tvcall);
        callDetails();
    }
    private void callDetails()
    {
        StringBuffer sb = new StringBuffer();
        Cursor managedCursor =managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
        int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
        int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
        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 callerName=managedCursor.getString(name);
            String callType=managedCursor.getString(type);
            String callDate=managedCursor.getString(date);
            Date callDayTime= new Date(Long.valueOf(callDate));
            String callDuaration= 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("\n Phone Number:--"+phNumber+"\n caller Name:--"+callerName+"\n call Type:--"+dir+"\n Call Date:--"+callDayTime+"\n call duration in sec:--"+callDuaration);
        sb.append("\n----------------------------");
        }
        managedCursor.close();
        call.setText(sb);

    }

1 个答案:

答案 0 :(得分:0)

按顺序排序。

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

尝试改变它。

Cursor managedCursor = managedQuery(CallLog.Calls.Content_URI, null, null, null, CallLog.Calls.DATE + " DESC");