I have a button that when pressed it should open the phone call mode with a dynamic number.
This method requires the CALL_PHONE permission. And when it is pressed the first time, it opens a dialog asking if I authorize the requested permission. And even if the person accepted, he does not continue the call. And I can not execute the number again, because it is a dynamic number and does not have the application to find out the number clicked.
I put a function that calls the number like this: makeCall("999999 numero dinâmico aqui");
Follow my code to better understand:
public void makeCall(String s) {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + s));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
requestForCallPermission();
} else {
startActivity(intent);
}
}
public void requestForCallPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) {
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, PERMISSION_REQUEST_CODE);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Aqui eu preciso arranjar um modo de executar o makeCall novamente, mas não tenho como saber qual será o numero.
}
break;
}
}
How can I pass some variable through the onRequestPermissionsResult so that the application knows which number to call?