Dharmesh Patel
Dharmesh Patel

Reputation: 91

Call forwarding is not working by using below code

When I try to forward call by this code nothing happened. I want call forward call on specific number. Please help me.

callforward("**21*MobileNo");// While incoming call.

private void callforward(String callForwardString) {


        PhoneCallListener phoneListener = new PhoneCallListener();
        TelephonyManager telephonyManager = (TelephonyManager)
                ctx.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
        Intent intentCallForward = new Intent(Intent.ACTION_CALL);
        Uri mmiCode = Uri.fromParts("tel", callForwardString, ("#"));
        intentCallForward.setData(mmiCode);
        System.out.println("Call FWD Number:"+callForwardString);
        if (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        ctx.startActivity(intentCallForward);



    }

Upvotes: 2

Views: 58

Answers (1)

Prince Dholakiya
Prince Dholakiya

Reputation: 3401

It should actually be pass # at the end of the mobile no.

callforward("**21*MobileNo#");// While incoming call.

// For the emulator, you have to pass **21*5556#.

Here # is more important to forwarding call.

Upvotes: 1

Related Questions