Android studio send mail with extra text mobile model
To send an email with extra text, including the mobile model, from an Android app using Android Studio, you can use the Intent
class to send an email intent. Here's an example:
First, add the following permissions to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
Then, create a button in your layout file and set an OnClickListener
to send the email:
<Button
android:id="@+id/send_email_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Email" />
// In your activity or fragment
Button sendEmailButton = findViewById(R.id.send_email_button);
sendEmailButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get the device's mobile model
String mobileModel = Build.MODEL;
// Create the email intent
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Test Email");
emailIntent.putExtra(Intent.EXTRA_TEXT, "This is a test email sent from an Android app. The mobile model is: " + mobileModel);
// Start the email intent
startActivity(Intent.createChooser(emailIntent, "Send Email"));
}
});
In this example, we're using the Build.MODEL
property to get the device's mobile model. We're then creating an Intent
with the ACTION_SEND
action and setting the email address, subject, and body of the email. The EXTRA_TEXT
extra is used to add the extra text, including the mobile model, to the email body.
When the user clicks the button, the email intent will be started, and the user will be prompted to choose an email app to send the email. The email app will then display the email with the subject, body, and attachments (if any).
Note that this code will only work if the user has an email app installed on their device. If the user doesn't have an email app installed, the intent will be ignored.