Professional Documents
Culture Documents
Practical 30
Practical 30
<Button recipientEditText =
findViewById(R.id.recipientEditText); Toast.makeText(MainActivity.this,
subjectEditText = "There are no email clients installed.",
findViewById(R.id.subjectEditText); Toast.LENGTH_SHORT).show();
messageEditText = }
findViewById(R.id.messageEditText); }
sendButton = }
findViewById(R.id.sendButton);
sendButton.setOnClickListener(new
View.OnClickListener() {
Manifest.xml
@Override <?xml version="1.0" encoding="utf-8"?>
public void onClick(View v) { <manifest
String recipient = xmlns:android="http://schemas.android.com/
recipientEditText.getText().toString(); apk/res/android"
String subject =
subjectEditText.getText().toString(); xmlns:tools="http://schemas.android.com/to
String message = ols">
messageEditText.getText().toString(); <uses-permission
android:name="android.permission.SEND_SM
if (!recipient.isEmpty() && ! S"/>
subject.isEmpty() && !message.isEmpty()) { <uses-permission
sendEmail(recipient, subject, android:name="android.permission.READ_PH
message); ONE_STATE"/>
} else {
Toast.makeText(MainActivity.this, <application
"Please enter recipient, subject, and android:allowBackup="true"
message", Toast.LENGTH_SHORT).show();
} android:dataExtractionRules="@xml/data_ext
} raction_rules"
});
} android:fullBackupContent="@xml/backup_ru
les"
private void sendEmail(String recipient, android:icon="@mipmap/ic_launcher"
String subject, String message) { android:label="@string/app_name"
Intent intent = new
Intent(Intent.ACTION_SEND); android:roundIcon="@mipmap/ic_launcher_r
intent.setType("message/rfc822"); ound"
intent.putExtra(Intent.EXTRA_EMAIL, android:supportsRtl="true"
new String[]{recipient}); android:theme="@style/Theme.Practical"
intent.putExtra(Intent.EXTRA_SUBJECT, tools:targetApi="31">
subject); <activity
intent.putExtra(Intent.EXTRA_TEXT, android:name=".MainActivity"
message); android:exported="true">
<intent-filter>
try { <action
android:name="android.intent.action.MAIN" /
startActivity(Intent.createChooser(intent, >
"Send email..."));
} catch <category
(android.content.ActivityNotFoundException android:name="android.intent.category.LAUN
ex) {
OUTPUT: