Search code examples
androidbroadcastreceiver

android Broadcastreceiver issue


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);




    }

Solution

  • 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.