From e12387e256862f3937dcc2bae4336070f1393ef3 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Mon, 7 Oct 2024 17:36:24 +0530 Subject: [PATCH] Fixed: "Send diagnostic report" function should open the user's email client. * Previously, other apps were appearing in the suggestions when sending the diagnostic report. We have improved our intent so that it now directly opens the user's email client to send the diagnostic report to us. --- .../kiwixmobile/core/error/ErrorActivity.kt | 29 ++++++++++++++----- .../kiwix/kiwixmobile/core/utils/Constants.kt | 1 + 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt index 80c240459..ace1d4875 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt @@ -19,6 +19,7 @@ package org.kiwix.kiwixmobile.core.error import android.annotation.SuppressLint import android.content.Intent +import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Process @@ -28,12 +29,17 @@ import androidx.core.content.FileProvider import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.launch import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent +import org.kiwix.kiwixmobile.core.R import org.kiwix.kiwixmobile.core.base.BaseActivity import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.getPackageInformation import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.getVersionCode +import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.queryIntentActivitiesCompat +import org.kiwix.kiwixmobile.core.compat.ResolveInfoFlagsCompat import org.kiwix.kiwixmobile.core.dao.NewBookDao import org.kiwix.kiwixmobile.core.databinding.ActivityKiwixErrorBinding +import org.kiwix.kiwixmobile.core.extensions.toast import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer +import org.kiwix.kiwixmobile.core.utils.CRASH_AND_FEEDBACK_EMAIL_ADDRESS import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.getCurrentLocale import org.kiwix.kiwixmobile.core.utils.files.FileLogger import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer @@ -90,7 +96,19 @@ open class ErrorActivity : BaseActivity() { private fun setupReportButton() { activityKiwixErrorBinding?.reportButton?.setOnClickListener { lifecycleScope.launch { - sendEmailLauncher.launch(Intent.createChooser(emailIntent(), "Send email...")) + val emailIntent = emailIntent() + val activities = + packageManager.queryIntentActivitiesCompat(emailIntent, ResolveInfoFlagsCompat.EMPTY) + if (activities.isNotEmpty()) { + sendEmailLauncher.launch(Intent.createChooser(emailIntent, "Send email...")) + } else { + toast( + getString( + R.string.no_email_application_installed, + CRASH_AND_FEEDBACK_EMAIL_ADDRESS + ) + ) + } } } } @@ -102,12 +120,9 @@ open class ErrorActivity : BaseActivity() { private suspend fun emailIntent(): Intent { val emailBody = buildBody() - return Intent(Intent.ACTION_SEND).apply { - type = "text/plain" - putExtra( - Intent.EXTRA_EMAIL, - arrayOf("android-crash-feedback@kiwix.org") - ) + return Intent(Intent.ACTION_SENDTO).apply { + data = Uri.parse("mailto:") + putExtra(Intent.EXTRA_EMAIL, arrayOf(CRASH_AND_FEEDBACK_EMAIL_ADDRESS)) putExtra(Intent.EXTRA_SUBJECT, subject) putExtra(Intent.EXTRA_TEXT, emailBody) val file = fileLogger.writeLogFile( diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt index fa51b9e12..e2732e7d8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt @@ -18,6 +18,7 @@ package org.kiwix.kiwixmobile.core.utils const val TAG_KIWIX = "kiwix" +const val CRASH_AND_FEEDBACK_EMAIL_ADDRESS = "android-crash-feedback@kiwix.org" // Request stuff const val REQUEST_STORAGE_PERMISSION = 1