//TODO: Add your package name here (e.g. com.maad.candroid) import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void callButton(View view) { /*Starting from Android Marshmallow 6.0, we have to request every dangerous permission via code Before 6.0: https://developer.android.com/guide/topics/permissions/overview#install-time_requests_android_511_and_below 6.0 and higher: https://developer.android.com/guide/topics/permissions/overview#runtime_requests_android_60_and_higher so, in this if statement condition we are checking if the request has been granted, if the condition is "true" which means that the permission is granted, so we will make our intent, and if the condition is "false" then we will show a request permission dialog via the requestPermissions method. */ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { //You can use: Intent phoneIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" /*+ NUMBER_TO_CALL*/)); startActivity(phoneIntent); //or you can use this alternative: //Intent phoneIntent = new Intent(Intent.ACTION_CALL); //phoneIntent.setData(Uri.parse("tel:" /*+ NUMBER_TO_CALL*/)); //startActivity(phoneIntent); } else { requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 101); } } }