0

Im developing an application,which blocks all outgoing calls and then after blocking that call ,another new call is initiated to a predefined number...

My problem is that,when i block the call using a broadcastreceiver,the second call which i programmatically initiate is also getting blocked...

Is any method to unregister the broadcast after blocking the first call,or any other method or technique???

This is my broadcastreceiver which i implemented for my app...

public class CallListenerActivity extends BroadcastReceiver {

Uri uri;

    @Override
    public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();

            if(bundle == null)
                return;


            String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

            Log.i("@@@OutgoingCallReceiver",phonenumber);
            Log.i("@@@OutgoingCallReceiver",bundle.toString());

            String info = "Detect Calls sample application\nOutgoing number: " + phonenumber;

           Toast.makeText(context, info, Toast.LENGTH_LONG).show();



           String phoneNumber = "5556";
           Uri uri = Uri.fromParts("tel", phoneNumber, null);

           Intent callIntent = new Intent(Intent.ACTION_CALL, uri);
           callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           context.startActivity(callIntent);




    }
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
subrussn90
  • 1,142
  • 1
  • 14
  • 27
  • I am doing something similar HERE!!! http://stackoverflow.com/questions/14571564/android-pendingintent-extras-not-received-by-broadcastreceiver/14612215#14612215 – Etienne Lawlor Jan 31 '13 at 07:48

2 Answers2

1

You can use store a check when you are initiating a call and after the completion of the call mark it. For this this check you can use SharedPreference.

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
  • Vineet,but how can the second call be made escaped from the broadcastreceiver? – subrussn90 Jan 09 '12 at 08:34
  • take boolean and set it true and store it in sharedpreference and then when you get the call in your broadcast then check this bool if it is true then escape and set it false on call completion... – Vineet Shukla Jan 09 '12 at 08:47
  • but the broadcast is still catching the second call...i do not want to check the second outgoing call with my broadcastreceiver.... – subrussn90 Jan 09 '12 at 08:53
1

You could try starting your original (CallListenerActivity? The one which registered the broadcast receiver) activity again using a flag stored as extra in the intent. Evaluate the intent in your activity and unregister the broadcast receiver if you see the flag in the extras. Then start the the call activity as shown in your example code.

Stefan
  • 4,645
  • 1
  • 19
  • 35