5

with statrtActivity(callIntent), call goes and then i have to wait for few seconds and end automatically. to end up my call i have taken mycalss extends Broadcastreceiver then in that onreceive() i implemented.in that method i got only to set old number and newnumber and toast is printing. What i want exactly is to end call what i need to write. and how to call onreceive method from my class? plase help me. i didnt get anywhere.

 @Override
                public void onReceive(Context context, Intent intent) {                                 
                    final String oldNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);         
                    this.setResultData(newPhNnumber);                                                   
                    final String newNumber = this.getResultData();
                    if((newNumber!=null)&&(newNumber!=oldNumber))
                    {
                    String msg = "Intercepted outgoing call. Old number " + oldNumber + ", new number " + newNumber;
                    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                    this.abortBroadcast();----> what it does?
                }
PhatHV
  • 8,010
  • 6
  • 31
  • 40
Deepu Mandy
  • 117
  • 12

2 Answers2

3

You may try this:

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
    Class c = Class.forName(tm.getClass().getName());
    Method m = c.getDeclaredMethod("getITelephony");
    m.setAccessible(true);
    ITelephony telephonyService = (ITelephony) m.invoke(tm);

    telephonyService.endCall();

} catch (Exception e) {
    e.printStackTrace();
}
PhatHV
  • 8,010
  • 6
  • 31
  • 40
  • I tried your code but that doesn't seem to end the call. I used `TelephonyManager.CALL_STATE_OFFHOOK` to check for state and then to end it. Any idea? – Gowtham Jan 14 '15 at 05:50
0

you simply abort outgoing call through following code

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    if (intent.getAction()
            .equals("android.intent.action.NEW_OUTGOING_CALL")) {

        phoneNo = intent
                .getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        if (phoneNo.isBlocked(blockNo)) {
            setResultData(null);

        }
    }
}
Umang Kothari
  • 3,674
  • 27
  • 36