package com.example.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

        Button launchButton = findViewById(R.id.activity_main_button_launch);
        launchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Create the text message with a string
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.setType("text/plain");
                sendIntent.putExtra(Intent.EXTRA_TEXT, "Un texte à partager");
                // Start the activity
                if (sendIntent.resolveActivity(getPackageManager()) != null) {
                    startActivity(sendIntent);
                }

//                // Always use string resources for UI text.
//                // This says something like "Share this photo with"
//                String title = getResources().getString(R.string.chooser_title);
//                // Create intent to show the chooser dialog
//                Intent chooser = Intent.createChooser(sendIntent, title);
//                // Verify the original intent will resolve to at least one activity
//                if (sendIntent.resolveActivity(getPackageManager()) != null) {
//                    startActivity(chooser);
//                }

            }
        });
    }
}
