简体   繁体   English

如何在通话完成后读取通话记录并存储在日志中?

[英]how to read call logs after call finished and stored in logs?

I am reading call logs after call finish, according this if call is connected then call duration is greater than 0. If duration is greater than 0, I schedule next call on that number after 2 days. 我正在通话结束后阅读通话记录,根据此情况,如果呼叫已连接,则呼叫持续时间大于0.如果持续时间大于0,我会在2天后安排对该号码的下一次呼叫。 If call duration is 0 then I schedule next call on that number after 1 day. 如果通话时长为0,那么我会在1天后安排对该号码的下一次通话。

My problem is that when call is connected then it scheduled correctly, but when call is not connect then previous text is shows. 我的问题是,当呼叫连接然后它正确安排,但当呼叫未连接时,则显示前一个文本。 Sometimes it is correct and sometimes is not correct. 有时它是正确的,有时是不正确的。

I open this activity from receiver. 我从接收器打开这个活动。 Please provide better solution. 请提供更好的解决方案

Following is my code: 以下是我的代码:

@Override
protected void onResume() {
     /**
      * this values only set when call maked from app then it w
      * ill set auto filled some of filled in follow up
      *
      */
    if(flag!=null && flag.equalsIgnoreCase("Followup")/*&& state!=true*/){
        if(SharedPrefs.getBoolean(this, SharedPrefs.PREFS_AUTH, SharedPrefs.
           KEY_SCHEDULE_NEXT_FOLLOWUP, false))
            {
             findViewById(R.id.rl_followUp).setVisibility(View.VISIBLE);
            } else {
             findViewById(R.id.rl_followUp).setVisibility(View.GONE);
            }
        getCallDetails();

        /*  
        String strDateFormat = "hh:mm a";
        SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
        calendar=Calendar.getInstance();
        */
        if(callDuration > 0){
           tvDateText.setText(timeInMilies(2));
           etFUComments.setText("Call is done");
        } else {
           tvDateText.setText(timeInMilies(1));
           etFUComments.setText(getResources().
               getString(R.string.call_not_connected_detail));
        }
    }
    super.onResume();
}

private void getCallDetails() {
    StringBuffer sb = new StringBuffer();
    String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
    /* Query the CallLog Content Provider */
    managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
            null, null, strOrder);
    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
    duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
    sb.append("Call Log :");
    if  (managedCursor.moveToNext()) {
        phNum = managedCursor.getString(number);
        String callTypeCode = managedCursor.getString(type);
        String strcallDate = managedCursor.getString(date);
        callDate = new Date(Long.valueOf(strcallDate));
        callDuration =Integer.parseInt(managedCursor.getString(duration));
        String callType = null;
        int callcode = Integer.parseInt(callTypeCode);
        switch (callcode) {
            case CallLog.Calls.OUTGOING_TYPE:
                callType = "Outgoing";
                break;
            case CallLog.Calls.INCOMING_TYPE:
                callType = "Incoming";
                break;
            case CallLog.Calls.MISSED_TYPE:
                callType = "Missed";
                break;
        }
    }
    managedCursor.close();
}


public String timeInMilies(int day){
    Date date=new Date();//(86400000*2)
    long time= date.getTime();
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time + (86400000 * day));
    //etFUComments.setText(String.valueOf(formatter.format(calendar.getTime())));
    return String.valueOf(formatter.format(calendar.getTime()));
}

您可以延迟打开活动,因为在通话后您突然打开活动并且在该时间内没有当前日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM