Intent call action doesn't work on Marshmallow
Method to make call
public void onCall() {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.CALL_PHONE},
"123");
} else {
startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:12345678901")));
}
}
Check permission
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 123:
if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
onCall();
} else {
Log.d("TAG", "Call Permission Not Granted");
}
break;
default:
break;
}
}
Beginning in android 6.0 (API 23), dangerous permissions must be declared in the manifest AND you must explicitly request that permission from the user. According to this list, CALL_PHONE
is considered a dangerous permission.
Every time you perform an operation that requires a dangerous permission, you must check if that permission has been granted by the user. If it has not, you must request that it be granted. See Requesting Permissions at Run Time on Android Developers.