I wanted to implement an application that prevents calls such as a firewall. When I debug my application, I find that when I call the onCallStateChanged () function in the PhoneStateListener interface is called three times. As a result, preventing one call can result in three logs. I'm so confused !!
my code is:
@Override public void onCallStateChanged(int state, String incomingNumber) { try { if (state == TelephonyManager.CALL_STATE_RINGING && PhoneUtil.getITelephony(tpm).isRinging()) { String flag = isBlockCall(myContext, myHelper, myTypes, incomingNumber); if (flag.length() > 0) { blockCall(); myHelper.insertLog(new String[] { flag, incomingNumber, String.valueOf(System.currentTimeMillis()), null }); showNotification(myContext, incomingNumber, System.currentTimeMillis()); } } } catch (Exception e) { e.printStackTrace(); } super.onCallStateChanged(state, incomingNumber); } }, PhoneStateListener.LISTEN_CALL_STATE);
source share