0
I have a button that when pressed it should open the telephone call mode with a dynamic number.
This method requires permission CALL_PHONE. And when pressed the first time, it opens a dialog asking if I authorize the requested permission. And even if the person accepts, he doesn’t continue the connection. And I do not have to run the number again, because it is a dynamic number and there is no way the application to find out what was the number clicked.
I put a function that calls the number that way: 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 the app knows which number to call?
Ever thought about saving the number in a class variable?
– perozzo