-3

I'm busy making my first android app and i'm looking to create the following option: Whenn someone clicks on "Contact us" from "activit_main_drawer.xml" they will directly call "phone number"

Is there anyone who can help me? :)

This is how the "Button" is called

    <item
        android:id="@+id/nav_belnu"
        android:icon="@drawable/ic_phone_square_solid"
        android:title="BEL nu" />
Eric Osman
  • 65
  • 1
  • 5

1 Answers1

0

Inside the onclick listener of your button, you can proceed this way, remember to add call permission in the manifest file of your project:

private void makeCall(String phoneNumber){
        try {
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + phoneNumber));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                startActivity(intent);
            }catch (Exception e)
            {
                e.printStackTrace();
            }
}
Gratien Asimbahwe
  • 1,606
  • 4
  • 19
  • 30