0

``there are several answer available for rejecting incoming call in android but they all are not working in android 10 and above. is there any solution we can do it programmatically.

Thank you in Advancetext

I have tried all the solution available in StackOverflow using Broadcast receiver and also used inCall Service.

here's what i have tried but its not working

public class MainActivity extends AppCompatActivity { private static final int PERMISSION_REQUEST_CODE = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
            != PackageManager.PERMISSION_GRANTED) {
        // Permission is not granted, request it
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.READ_PHONE_STATE},
                PERMISSION_REQUEST_CODE);
    } else {
        // Permission is already granted, start the inCallService
        startService(new Intent(this, CallService.class));
    }
    /*checkPermission(Manifest.permission.READ_PHONE_STATE, 100);
    checkPermission(Manifest.permission.READ_CALL_LOG,200);
    Intent intent = new Intent(this, CallService.class);
    startService(intent);*/
}

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == PERMISSION_REQUEST_CODE) {
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        // Permission is granted, start the inCallService
        startService(new Intent(this, CallService.class));
    } else {
        // Permission is denied, show an error message
        Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
    }
}

} }

And in callService:

public class CallService extends InCallService {

@Override
public void onCallAdded(Call call) {
    Log.e("onCallAdded", "working");
    super.onCallAdded(call);
    // Reject the incoming call
    call.reject(false, null);
    Toast.makeText(this, "Call Rejected Successfully", Toast.LENGTH_SHORT).show();
}

}

but this code doesnt reject any incoming call `

0 Answers0