How to make call transfer

1

I have an app that transfers calls but from version 6+ it does not work I've tried this:

btn_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri uri2 = Uri.parse("tel:4");
                intent.setData(uri2);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (ActivityCompat.checkSelfPermission(ServicioCallerOverride.this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
                    startActivity(intent);
                }
            }
        });

The result is: The transfer could not be made. It does not give an error in the application.

    
asked by JoseMa 20.06.2018 в 11:17
source

1 answer

2

By clicking on the button you are detecting if the permission exists, if this is the case you do the Intent, therefore the Intent will not be done since you must first require permissions.

Add permission request:

 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE},
                    122);

This would be the code:

btn_transfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_CALL);
                Uri uri2 = Uri.parse("tel:4");
                intent.setData(uri2);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (ActivityCompat.checkSelfPermission(ServicioCallerOverride.this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
                    startActivity(intent);
                }else{ //si no existe permiso, los requiere.
                    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE},
                    122);
               }



            }
        });

Important: the user has to accept the permission forcibly, if he does not accept it there will be no way to make the call, this for devices with android 6.0 or later

    
answered by 20.06.2018 в 16:50