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() { if(flag!=null && flag.equalsIgnoreCase("Followup")){ 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(); 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"; 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();
source share