Разрешение в AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
Полный код:
private void onCallBtnClick(){
if (Build.VERSION.SDK_INT < 23) {
phoneCall();
}else {
if (ActivityCompat.checkSelfPermission(mActivity,
Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
phoneCall();
}else {
final String[] PERMISSIONS_STORAGE = {Manifest.permission.CALL_PHONE};
//Asking request Permissions
ActivityCompat.requestPermissions(mActivity, PERMISSIONS_STORAGE, 9);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
boolean permissionGranted = false;
switch(requestCode){
case 9:
permissionGranted = grantResults[0]== PackageManager.PERMISSION_GRANTED;
break;
}
if(permissionGranted){
phoneCall();
}else {
Toast.makeText(mActivity, "You don't assign permission.", Toast.LENGTH_SHORT).show();
}
}
private void phoneCall(){
if (ActivityCompat.checkSelfPermission(mActivity,
Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:12345678900"));
mActivity.startActivity(callIntent);
}else{
Toast.makeText(mActivity, "You don't assign permission.", Toast.LENGTH_SHORT).show();
}
}