MANIFEST+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="it.unibo.stradivarius.intentdialer">

    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.IntentDialer">

        <activity android:name=".SelectorActivity"></activity>

        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
MAIN XML ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type in the number"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editTextPhone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="phone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"/>

    <TextView
        android:id="@+id/prefixText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextPhone"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        />

    <Button
        android:id="@+id/buttonPrefix"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Choose Prefix"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/prefixText" />

    <Button
        android:id="@+id/buttonCall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Call!"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />
SELECTOR XML ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SelectorActivity">

    <Button
        android:id="@+id/buttonUK"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="0044"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/buttonIT"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="0039"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonUK" />
</androidx.constraintlayout.widget.ConstraintLayout>
MAIN ACTIVITY *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class MainActivity extends AppCompatActivity {

    static final int REQUEST_CODE = 0;
    static final int PERMISSION_CODE = 0;

    TextView prefix;
    EditText number;
    ActivityResultLauncher<Intent> mLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            new ActivityResultCallback<ActivityResult>() {
                @Override
                public void onActivityResult(ActivityResult result) {
                    Intent data = result.getData();
                    String sResult = data.getExtras().getString("prefix");
                    prefix.setText(sResult);
                }
            });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        prefix = findViewById(R.id.prefixText);
        number = findViewById(R.id.editTextPhone);

        Button btnPrefix = findViewById(R.id.buttonPrefix);
        btnPrefix.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                ComponentName componentName =
                        new ComponentName(getApplicationContext(), SelectorActivity.class);
                i.setComponent(componentName);
                // startActivityForResult(i, REQUEST_CODE);
                mLauncher.launch(i);
            }
        });

        Button btnCall = findViewById(R.id.buttonCall);
        btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContextCompat.checkSelfPermission(getApplicationContext(),
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    requestPermissions();
                } else {
                    makeCall();
                }
            }
        });
    }

    void requestPermissions(){
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.CALL_PHONE},
                PERMISSION_CODE);
    }

    void makeCall() {
        Intent i = new Intent(Intent.ACTION_CALL);
        String uri = "tel:" + prefix.getText() + number.getText();
        i.setData(Uri.parse(uri));
        startActivity(i);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        String result = data.getExtras().getString("prefix");
        prefix.setText(result);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == PERMISSION_CODE) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                makeCall();
            }
        }
    }
}
SELECTOR ACTIVITY+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class SelectorActivity extends AppCompatActivity {

    Button btnUK;
    Button btnIT;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_selector);

        btnUK = findViewById(R.id.buttonUK);
        btnUK.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = getIntent();
                setResult(RESULT_OK, i);
                i.putExtra("prefix", btnUK.getText());
                finish();
            }
        });
        btnIT = findViewById(R.id.buttonIT);
        btnIT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = getIntent();
                setResult(RESULT_OK, i);
                i.putExtra("prefix", btnIT.getText());
                finish();
            }
        });
    }
}
