Good morning, I'm developing an application, where I have the following doubt. I want to send an e-mail form using Intent's. The code is apparently OK, but when I click the "Send" button the program does nothing. Please, I would like you to help me. Here is the Java and XML code:
JAVA
package pt.penafielverde.serpeagu.serpaguv110.agu;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class enviarmail extends AppCompatActivity {
Button enviar = findViewById(R.id.enviar);
final EditText assunto = findViewById(R.id.assunto);
EditText operador = findViewById(R.id.operador);
final EditText corpoemail = findViewById(R.id.corpoemail);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enviar_email);
enviar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendMail();
assunto.setText("");
operador.setText("");
corpoemail.setText("");
}
private void sendMail() {
String recipientList = "[email protected]";
String[] recipients = recipientList.split(",");
String subject = assunto.getText().toString();
String message = corpoemail.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message + "Mensagem enviada por," + operador);
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Escolha o cliente email, por onde deseja enviar a mensagem :"));
}
;
});
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="pt.penafielverde.serpeagu.serpaguv110.agu.enviarmail">
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="66dp"
android:layout_marginTop="51dp"
android:text="Operador.:" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="COMUNICAÇÃO "
android:textColor="@android:color/holo_green_light"
android:textStyle="bold" />
<TextView
android:id="@+id/assunto_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/textView10"
android:layout_alignParentTop="true"
android:layout_marginTop="81dp"
android:text="Assunto.:" />
<EditText
android:id="@+id/operador"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_alignBaseline="@+id/textView10"
android:layout_toEndOf="@+id/textView10"
android:ems="10"
android:inputType="textPersonName"
android:textSize="12sp" />
<EditText
android:id="@+id/assunto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView10"
android:layout_toEndOf="@+id/textView10"
android:ems="10"
android:inputType="textPersonName"
android:textSize="12sp" />
<EditText
android:id="@+id/corpoemail"
android:layout_width="334dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="154dp"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/corpoemail"
android:layout_alignStart="@+id/corpoemail"
android:layout_marginBottom="-154dp"
android:text="Descrição da Anómalia" />
<Button
android:id="@+id/enviar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="17dp"
android:text="enviar" />
</RelativeLayout>