Tuesday, October 5, 2021

Email Send Fill Automatic in Android

 

àEmail sending Coding(filled automatic):-

 

Xml code:-

<?xml version="1.0" encoding="utf-8"?>
<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">


    <
Button
       
android:id="@+id/button"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Button"
       
tools:layout_editor_absoluteX="110dp"
       
tools:layout_editor_absoluteY="144dp" />

</
androidx.constraintlayout.widget.ConstraintLayout>

 

Java code:-

package com.example.emaiautomatic;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
Button
button;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
       
button=findViewById(R.id.button);
       
button.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
                Log.i(
"Send email", "");

                String[] TO = {
"someone@gmail.com"};
                String[] CC = {
"xyz@gmail.com"};
                Intent emailIntent =
new Intent(Intent.ACTION_SEND);
                emailIntent.setData(Uri.parse(
"mailto:"));
                emailIntent.setType(
"text/plain");


                emailIntent.putExtra(Intent.
EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.
EXTRA_CC, CC);
                emailIntent.putExtra(Intent.
EXTRA_SUBJECT, "Your subject");
                emailIntent.putExtra(Intent.
EXTRA_TEXT, "Email message goes here");

               
try {
                    startActivity(Intent.createChooser(emailIntent,
"Send mail..."));
                    finish();
                    Log.i(
"Finished sending email...", "");
                }
catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(MainActivity.
this,
                           
"There is no email client installed.", Toast.LENGTH_SHORT).show();
                }

            }
        });


    }
}

 

No comments:

Post a Comment

Activity Navigation One Activity to another Activity

Main Activity :-   <? xml version ="1.0" encoding ="utf-8" ?> < RelativeLayout xmlns: android ="http://sch...