How To Stop Phone Calls To Be Log In The Call Log On Android
I'm writing an application that block some phone calls. I use a broadcast receiver to listen to incoming calls:
Solution 1:
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.
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.
Here's the code :
@OverridepublicvoidonReceive(Context context, Intent intent) {
Log.i(LOG_TAG, "Début InComingCallReceiver.onReceive");
Log.i(LOG_TAG, "IS ORDERED = " + this.isOrderedBroadcast());
Bundleextras= intent.getExtras();
if (extras != null) {
Stringstate= extras.getString(TelephonyManager.EXTRA_STATE);
Log.i(LOG_TAG, state);
StringphoneNumber= 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");
TelephonyManagertelephony= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Classc= Class.forName(telephony.getClass().getName());
Methodm= 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());
}
}
}
elseif (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");
intnbRowDeleted= context.getContentResolver().delete(CallLog.Calls.CONTENT_URI, CallLog.Calls.NUMBER + " = ?", newString[] {phoneNumber});
Log.i(LOG_TAG, nbRowDeleted + " Row(s) Deleted");
}
}
}
}
Solution 2:
I doubt you can prevent the call from showing up in the call log. Instead of preventing the call from getting added to the log try opening the call log and deleting it.
Post a Comment for "How To Stop Phone Calls To Be Log In The Call Log On Android"