Search code examples
androidcall

Make calls from custom outgoing screen


I want to replace the outgoing screen and make call through that custom screen. I succeed to bring custom screen but I could not make calls. If I use ACTION.CALL then it call the Default outgoing screen.

public class OutgoingCallBroadcastReciver extends BroadcastReceiver {
    Context c;
    public OutgoingCallBroadcastReciver() {

    }

    @Override
    public void onReceive(final Context context, final Intent intent) {
        final String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        c=context;
        setResultData(null);
        setResultData(number);
        callActionHandler.postDelayed(runRingingActivity, 1000);

    }

    Handler callActionHandler = new Handler();
    Runnable runRingingActivity = new Runnable(){

        @Override
        public void run()
        {
            Intent intentPhoneCall = new Intent(c, OutgoingScreen.class);
            intentPhoneCall.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            c.startActivity(intentPhoneCall);
        }

    };
}

Solution

  • For outgoing calls I make custom work around and created custom permission of outgoing reciever in manifest.

    I had called the activity after a delay using handler.

    Hope i will work for you.

    Please check the below code.

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        mcontext = context;
        setResultData(null);
        dialphonenumber = getResultData();
        if dialphonenumber == null)
        {
            dialphonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        }
        setResultData(dialphonenumber);
        callActionHandler.postDelayed(runRingingActivity, 1000);
    }
    
    
    Handler callActionHandler = new Handler();
    Runnable runRingingActivity = new Runnable() 
    {
        @Override
        public void run() 
        {
    
            Intent intentPhoneCall = new Intent(mcontext, OutgoingCallActivity.class);
            intentPhoneCall.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intentPhoneCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mcontext.startActivity(intentPhoneCall);
        }
    };
    

    Hope it will work for you.

    Let me know if you have any issue.