3

my VoiP-client would like to block all incoming calls to the phone while my own call is taking place. Is it possible to do this somehow?

2 Answers 2

4

Yes you can block incoming calls. Using this code

 String phonestate = bundle.getString(TelephonyManager.EXTRA_STATE);

 try 
    {
        if (TelephonyManager.EXTRA_STATE_RINGING.equalsIgnoreCase(phonestate)) 
        {
            try 
            {
                TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                Class c = Class.forName(tm.getClass().getName());
                Method m = c.getDeclaredMethod("getITelephony");
                m.setAccessible(true);
                telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm);
            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }

            if (prefStatus != null) 
            {
                if (count == 1) 
                {
                    telephonyService.endCall();
                    String prefLoginemail = myloginpref.getString("emailid", null);
                    System.out.println(printdata + " prefLoginemail :: "+ prefLoginemail);

                    Global.mNotificationManager = (NotificationManager) mxcontext.getSystemService(Context.NOTIFICATION_SERVICE);
                    notifyDetails = new Notification(com.CellPhoneTerror.R.drawable.icon1,"CellPhoneTerror!", System.currentTimeMillis());
                    myIntent = PendingIntent.getActivity(mxcontext, 0, new Intent(mxcontext, clsHomePage.class), 0);

                    notifyDetails.setLatestEventInfo(mxcontext,"You Got a Call from Blocked Number.", "",myIntent);
                    notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
                    Global.mNotificationManager.notify(Global.SIMPLE_NOTFICATION_ID,notifyDetails);

                }
            }
        }
        if (prefIncomingBlock.equals("true")) 
        {
            if (TelephonyManager.EXTRA_STATE_IDLE.equalsIgnoreCase(phonestate)) 
            {
                if (count == 0) 
                {
                    System.out.println("if Cellphoneterror:"+ Global.clsIncomingNum);
                    Intent block = new Intent(context, dialogbox1.class);
                    block.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(block);
                }
            }
        }
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }

Thanks.

3
  • -1 I think it is pretty that the asker wanted to know how to do this.
    – Elemental
    Commented Jul 27, 2011 at 9:19
  • Sorry friends, But my network was down so I was not able to put example here. Anyway Thanks for comment.
    – anddev
    Commented Jul 27, 2011 at 12:52
  • How can you avoid the delay and sometimes one or two rings before its blocked?
    – powder366
    Commented Jul 6, 2014 at 15:40
1

Not with the current SDK no, You can monitor incoming calls and give the user the option to answer with your application instead of the native app

2
  • How is the user offered to choose app to answer with, trough an intentchooser? Thanks for you help. Commented Feb 26, 2010 at 12:49
  • Yep you can register to listen for that intent and start your application on that intent Commented Feb 26, 2010 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.