content: package Guzzlecode.IntentCaller.fragment;
  
  import android.Manifest;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.net.Uri;
  import android.os.Build;
  import android.os.Bundle;
  
  import androidx.core.app.ActivityCompat;
  import androidx.core.content.ContextCompat;
  import androidx.fragment.app.Fragment;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.EditText;
  
  import Guzzlecode.IntentCaller.R;
  
  
  public class PhoneFragment extends Fragment {
  
      Button btCallNow, btToAppsContact;
      EditText etPhoneNumber;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_phone, container, false);
          btCallNow = (Button)view.findViewById(R.id.btnCallNow);
          btToAppsContact = (Button)view.findViewById(R.id.btGoToApp);
          etPhoneNumber = (EditText)view.findViewById(R.id.edtNomorPonsel);
  
          btCallNow.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  final int REQUEST_PHONE_CALL = 1;
                  Intent callIntent = new Intent(Intent.ACTION_CALL);
                  callIntent.setData(Uri.parse("tel:+62" + etPhoneNumber.getText().toString()));
                  if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
                      if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){
                          ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CALL_PHONE}, REQUEST_PHONE_CALL);
                      } else {
                          startActivity(callIntent);
                      }
                  }
              }
          });
  
          btToAppsContact.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(Intent.ACTION_DIAL);
                  // Send phone number to intent as data
                  intent.setData(Uri.parse("tel:+62" + etPhoneNumber.getText().toString()));
                  // Start the dialer app activity with number
                  startActivity(intent);
              }
          });
  
          return view;
      }
  }