-1
I am making a form that will be sent by email, I have already created the email of gmail to use in the application, I have imported the necessary libraries, added permissions in Manifest, the code does not show errors but also does not send the email. here is the layout of the form called requests:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:textColor="@android:color/white"
/>
<EditText
android:id="@+id/etTO"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:background="@android:color/darker_gray"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject"
android:textColor="@android:color/white"
/>
<EditText
android:id="@+id/etSubject"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textColor="@android:color/white"
/>
<EditText
android:id="@+id/etMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="5"
android:background="@android:color/darker_gray"
/>
<Button
android:id="@+id/send_email_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send"
/>
my email Activity:
public class Send_email extends MainActivity {
Button btnSend;
EditText To;
EditText Subject;
EditText Message;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_email);
To = (EditText) findViewById(R.id.etTO);
Subject = (EditText) findViewById(R.id.etSubject);
Message = (EditText) findViewById(R.id.etMsg);
btnSend = (Button) findViewById(R.id.send_email_button);
btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to = To.getText().toString();
String subject = Subject.getText().toString();
String message = Message.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Select Email Client"));
}
});
}
When emulate the application on mobile and open the form, it’s like you haven’t even run the code, just fill in the fields. Can anyone tell me what I’m doing wrong or missing for my code to work?