Fonction envoi Mail
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package fr.svpro.radiomercure;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
@@ -10,6 +15,7 @@ public class MailActivity extends AppCompatActivity {
|
||||
|
||||
private EditText etSujet, etMessage;
|
||||
private Button btnEnvoyer;
|
||||
private static final String EMAIL_TO = "regie@radiomercure.fr";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -20,8 +26,36 @@ public class MailActivity extends AppCompatActivity {
|
||||
etMessage = findViewById(R.id.etMessage);
|
||||
btnEnvoyer = findViewById(R.id.btnEnvoyer);
|
||||
|
||||
btnEnvoyer.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//Champ sujet non vide
|
||||
if (TextUtils.isEmpty(etSujet.getText().toString().trim())){
|
||||
etSujet.setError(getString(R.string.et_err));
|
||||
} else {
|
||||
envoiMail();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void envoiMail() {
|
||||
String[] TO = {EMAIL_TO};
|
||||
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_SUBJECT, etSujet.getText().toString());
|
||||
emailIntent.putExtra(Intent.EXTRA_TEXT, etMessage.getText().toString());
|
||||
|
||||
try {
|
||||
startActivity(Intent.createChooser(emailIntent, "Envoi de votre message..."));
|
||||
finish();
|
||||
} catch (android.content.ActivityNotFoundException ex) {
|
||||
Toast.makeText(this, R.string.mailclient_err, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout 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:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -15,7 +16,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimaryVariant"
|
||||
android:text="Contactez-nous"
|
||||
android:text="@string/titre_mail"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.Material3.BodyLarge"
|
||||
android:textColor="@color/white"
|
||||
@@ -28,7 +29,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPersonName"
|
||||
android:minHeight="48dp"
|
||||
android:hint="Sujet de votre message" />
|
||||
android:hint="@string/etSujet_hint"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etMessage"
|
||||
@@ -38,7 +40,7 @@
|
||||
android:inputType="textMultiLine"
|
||||
android:lines="10"
|
||||
android:minHeight="48dp"
|
||||
android:hint="Votre message"/>
|
||||
android:hint="@string/etMessage_hint"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnEnvoyer"
|
||||
|
||||
@@ -21,4 +21,10 @@
|
||||
<string name="dialog_battery_titre">Désactiver l\'optimisation de la batterie ?</string>
|
||||
<string name="dialog_button_oui">Oui</string>
|
||||
<string name="dialog_button_non">Non</string>
|
||||
<string name="et_err">Veuillez renseigner ce cbamp !</string>
|
||||
<string name="titre_mail">Contactez-nous</string>
|
||||
<string name="etSujet_hint">Sujet de votre message</string>
|
||||
<string name="etMessage_hint">Votre message</string>
|
||||
<string name="mailclient_err">Aucun client mail trouvé !!</string>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user