Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It Look like there is no way to prevent the system to log the phone call in the call log. So we have to delete it from the call log. The problem is that the entry is added in the call log long after the phone call has been hang up and we do not see it in the database when we are in the onReceive method of the broadcast receiver.</p> <p>After a lot of research and tests, I came up with this simple solution. I make the thread sleep for 2 seconds befor deleting it.</p> <p>Here's the code :</p> <pre><code>@Override public void onReceive(Context context, Intent intent) { Log.i(LOG_TAG, "Début InComingCallReceiver.onReceive"); Log.i(LOG_TAG, "IS ORDERED = " + this.isOrderedBroadcast()); Bundle extras = intent.getExtras(); if (extras != null) { String state = extras.getString(TelephonyManager.EXTRA_STATE); Log.i(LOG_TAG, state); String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); Log.i(LOG_TAG, phoneNumber); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { if (phoneNumber.contains(PHONE_FILTER)) { Log.i(LOG_TAG, "Cancelling the incoming call"); TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(telephony); telephonyService.silenceRinger(); telephonyService.endCall(); } catch (Exception e) { Log.e(LOG_TAG,"Exception in InComingCallReceiver.onReceive"); Log.e(LOG_TAG,"ERROR: " + e.toString() + " Message: " + e.getMessage() + " --- " + e.getLocalizedMessage() + " Cause: " + e.getCause() + " StackTrace: " + e.getStackTrace()); } } } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { if (phoneNumber.contains(PHONE_FILTER)) { Log.i(LOG_TAG, "Waiting 2sec"); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.i(LOG_TAG, "After Waiting 2sec"); Log.i(LOG_TAG, "Deleting the incoming call from call log"); int nbRowDeleted = context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + " = ?", new String[] {phoneNumber}); Log.i(LOG_TAG, nbRowDeleted + " Row(s) Deleted"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload