How to read call logs after ending a call and saving to logs?

I read the call logs after the call ends, in accordance with this, if the call is connected, the call duration is greater than 0. If the duration is more than 0, I plan the next call to this number after 2 days. If the call duration is 0, I assign the next call to this number after 1 day.

My problem is that when the call is connected, it is correctly configured, but when the call does not connect, the previous text is displayed. Sometimes it’s right, and sometimes it’s wrong.

I open this operation from the receiver. Provide the best solution.

Below 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())); } 
+5
source share
1 answer

You can give some delay for opening activity, cause a sudden opening of activity after a call, and during this time there is no current log.

0
source

Source: https://habr.com/ru/post/1232559/


All Articles