Skip to content

Commit c26dd94

Browse files
committed
Adding handling when there is no email app on the device and the user clicks "send email in about".
1 parent 846da7b commit c26dd94

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

app/src/main/java/fr/berliat/hskwidget/domain/Utils.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,15 @@ class Utils {
6464
}
6565

6666
fun sendEmail(context: Context, address: String, subject: String = "", body: String = "") {
67-
context.startActivity(getOpenURLIntent(
68-
"mailto:$address?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body)))
67+
val intent = getOpenURLIntent(
68+
"mailto:$address?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body))
69+
70+
if (intent.resolveActivity(context.packageManager) != null) {
71+
context.startActivity(intent)
72+
} else {
73+
Toast.makeText(context, context.getString(R.string.about_email_noapp), Toast.LENGTH_LONG).show()
74+
copyToClipBoard(context, address)
75+
}
6976
}
7077

7178
fun playWordInBackground(context: Context, word: String) {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,5 @@ padding: 0;
288288
<string name="dictionary_item_altdefinition">Definition</string>
289289
<string name="dictionary_search_filter_hsk3definition_hint">Definition in HSK3</string>
290290
<string name="dbrestore_start">Database restoration started</string>
291+
<string name="about_email_noapp">No email client found. Address copied to clipboard.</string>
291292
</resources>

0 commit comments

Comments
 (0)