Email Activity | Android
Email Activity 1) java File
package com.example.myapplication; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import androidx.annotation.Nullable; public class EmailActivity extends Activity implements View.OnClickListener { EditText personsEmail, subject, yourName, phone,message; String EmailAdd, Subject, Name, Message, Phone; Button sendEmail; private void initializeVars() { // TODO Auto-generated method stub personsEmail = (EditText) findViewById(R.id.etEmails); subject = (EditText) findViewById(R.id.etSubject); yourName = (EditText) findViewById(R.id.etName); phone = (EditText) findViewById(R.id.etPhone); message = (EditText) findViewById(R.id.etMessage); sendEmail = (Button) findViewById(R.id.bSentEmail); sendEmail.setOnClickListener(this); } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.email); initializeVars(); } @Override public void onClick(View v) { String emailaddress[] = {EmailAdd} ; convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated(); String completeMessage = "My Name is " + Name + " My Contact number is " + Phone + ". Not only that but I hate when you " + '\n'+"My Message for you is " + Message + '\n' + "Thanks waiting for positive reply"; Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL,emailaddress); emailIntent.putExtra(Intent.EXTRA_CC,emailaddress); emailIntent.putExtra(android.content.Intent. EXTRA_SUBJECT,Subject); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent. EXTRA_TEXT,completeMessage); startActivity( emailIntent); } private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() { // TODO Auto-generated method stub EmailAdd = personsEmail.getText().toString(); Subject = subject.getText().toString(); Name = yourName.getText().toString(); Phone = phone.getText().toString(); Message = message.getText().toString(); } }
XML file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width= "match_parent" android:weightSum="100" android:layout_height= "match_parent"> <ScrollView android:layout_weight="30" android:layout_width= "fill_parent" android:layout_height="fill_parent" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height ="match_parent"> <TextView android:text="Email address(es):" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etEmails" > </EditText> <TextView android:text="Subject:" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etSubject" ></EditText> <TextView android:text="Your Name" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etName" ></EditText> <TextView android:text="Phone Number:" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etPhone" ></EditText> <TextView android:text="Message" android:layout_width="wrap_content" android:layout_height="wrap_content" ></TextView> <EditText android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/etMessage" ></EditText> </LinearLayout> </ScrollView> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_weight= "40" android:layout_height="fill_parent" > <Button android:text="Send Email" android:id="@+id/bSentEmail" android:layout_width="fill_parent" android:layout_height="fill_parent" ></Button> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_weight= "30" android:layout_height="fill_parent" > <AnalogClock android:id="@+id/analogClock1" android:layout_width="fill_parent" android:layout_height="fill_parent" ></AnalogClock> </LinearLayout> </LinearLayout>
0 comments:
Post a Comment