MainActivity.java:

package com.example.myapplication;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import android.widget.*;
import android.content.*;
import android.net.*;

public class MainActivity extends AppCompatActivity {

    Button btnCall, btnSms, btnEmail;

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

        btnCall = findViewById(R.id.callButton);
        btnSms = findViewById(R.id.smsButton);
        btnEmail = findViewById(R.id.emailButton);

        btnCall.setOnClickListener(v -> makeCall());
        btnSms.setOnClickListener(v -> sendSms());
        btnEmail.setOnClickListener(v -> sendEmail());
    }

    // FIX: don't crash when no app can handle the intent
    private void launch(Intent intent) {
        try {
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(this,
                    "No app found to handle this action",
                    Toast.LENGTH_SHORT).show();
        }
    }

    private void makeCall() {

        String phoneNumber = "9876543210";

        Intent callIntent = new Intent(Intent.ACTION_DIAL);
        callIntent.setData(Uri.parse("tel:" + phoneNumber));

        launch(callIntent);
    }

    private void sendSms() {

        String phoneNumber = "9876543210";
        String message = "Hello from implicit intent demo";

        Intent smsIntent = new Intent(Intent.ACTION_VIEW);
        smsIntent.setData(Uri.parse("sms:" + phoneNumber));
        smsIntent.putExtra("sms_body", message);

        launch(smsIntent);
    }

    private void sendEmail() {

        String[] recipients = {"someone@example.com"};
        String subject = "Hello from my app";
        String body = "This email was sent using an implicit intent.";

        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");

        emailIntent.putExtra(Intent.EXTRA_EMAIL, recipients);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(Intent.EXTRA_TEXT, body);

        launch(Intent.createChooser(
                emailIntent,
                "Send Email"
        ));
    }
}


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="30dp">

    <Button
        android:id="@+id/callButton"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="MAKE CALL"
        android:layout_marginBottom="20dp" />

    <Button
        android:id="@+id/smsButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="SEND SMS"
        android:layout_marginBottom="20dp" />

    <Button
        android:id="@+id/emailButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="SEND EMAIL" />

</LinearLayout>


AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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