So I try to make a app that will test if a phone can call phone numbers. And the main point is that when i push a call button and when the connection begins app ends a call and if there is no connection app shows an error. I managed to do a part where when button is clicked app calls a phone number but I can't come up with solution for ending a cal when there is connection (ringing). Is there any way to make this possible?
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String phone = "8686868686";
Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", phone, null));
startActivity(intent);
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
/*Context mContext = getApplicationContext();
TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
if (tm != null) {
boolean success = tm.endCall();
// success == true if call was terminated.
}*/
}
});