mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Introduced a new way to attech log file in email body without showing addtional apps in suggestion list
This commit is contained in:
parent
d7a0628eaa
commit
1f399f0fe7
@ -19,12 +19,13 @@ package org.kiwix.kiwixmobile.core.error
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.content.pm.ResolveInfo
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent
|
import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent
|
||||||
@ -96,10 +97,13 @@ open class ErrorActivity : BaseActivity() {
|
|||||||
activityKiwixErrorBinding?.reportButton?.setOnClickListener {
|
activityKiwixErrorBinding?.reportButton?.setOnClickListener {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val emailIntent = emailIntent()
|
val emailIntent = emailIntent()
|
||||||
val activities =
|
val activities = getSupportedEmailApps(emailIntent, supportedEmailPackages)
|
||||||
packageManager.queryIntentActivitiesCompat(emailIntent, ResolveInfoFlagsCompat.EMPTY)
|
val targetedIntents = createEmailIntents(emailIntent, activities)
|
||||||
if (activities.isNotEmpty()) {
|
if (activities.isNotEmpty() && targetedIntents.isNotEmpty()) {
|
||||||
sendEmailLauncher.launch(Intent.createChooser(emailIntent, "Send email..."))
|
val chooserIntent =
|
||||||
|
Intent.createChooser(targetedIntents.removeFirst(), "Send email...")
|
||||||
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedIntents.toTypedArray())
|
||||||
|
sendEmailLauncher.launch(chooserIntent)
|
||||||
} else {
|
} else {
|
||||||
toast(getString(R.string.no_email_application_installed))
|
toast(getString(R.string.no_email_application_installed))
|
||||||
}
|
}
|
||||||
@ -107,6 +111,53 @@ open class ErrorActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of supported email apps.
|
||||||
|
*/
|
||||||
|
private fun getSupportedEmailApps(
|
||||||
|
emailIntent: Intent,
|
||||||
|
supportedPackages: List<String>
|
||||||
|
): List<ResolveInfo> {
|
||||||
|
return packageManager.queryIntentActivitiesCompat(emailIntent, ResolveInfoFlagsCompat.EMPTY)
|
||||||
|
.filter {
|
||||||
|
supportedPackages.any(it.activityInfo.packageName::contains)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a list of intents for supported email apps.
|
||||||
|
*/
|
||||||
|
private fun createEmailIntents(
|
||||||
|
emailIntent: Intent,
|
||||||
|
activities: List<ResolveInfo>
|
||||||
|
): MutableList<Intent> {
|
||||||
|
return activities.map { resolveInfo ->
|
||||||
|
Intent(emailIntent).apply {
|
||||||
|
setPackage(resolveInfo.activityInfo.packageName)
|
||||||
|
}
|
||||||
|
}.toMutableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// List of supported email apps
|
||||||
|
private val supportedEmailPackages = listOf(
|
||||||
|
"com.google.android.gm", // Gmail
|
||||||
|
"com.zoho.mail", // Zoho Mail
|
||||||
|
"com.microsoft.office.outlook", // Outlook
|
||||||
|
"com.yahoo.mobile.client.android.mail",// Yahoo Mail
|
||||||
|
"me.bluemail.mail", // BlueMail
|
||||||
|
"ch.protonmail.android", // ProtonMail
|
||||||
|
"com.fsck.k9", // K-9 Mail
|
||||||
|
"com.maildroid", // Maildroid
|
||||||
|
"org.kman.AquaMail", // Aqua Mail
|
||||||
|
"com.edison.android.mail", // Edison Mail
|
||||||
|
"com.readdle.spark", // Spark
|
||||||
|
"com.gmx.mobile.android.mail", // GMX Mail
|
||||||
|
"com.fastmail", // FastMail
|
||||||
|
"ru.mail.mailapp", // Mail.ru
|
||||||
|
"ru.yandex.mail", // Yandex.Mail
|
||||||
|
"de.tutao.tutanota" // Tutanota
|
||||||
|
)
|
||||||
|
|
||||||
private val sendEmailLauncher =
|
private val sendEmailLauncher =
|
||||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
restartApp()
|
restartApp()
|
||||||
@ -114,15 +165,24 @@ open class ErrorActivity : BaseActivity() {
|
|||||||
|
|
||||||
private suspend fun emailIntent(): Intent {
|
private suspend fun emailIntent(): Intent {
|
||||||
val emailBody = buildBody()
|
val emailBody = buildBody()
|
||||||
return Intent(Intent.ACTION_SENDTO).apply {
|
return Intent(Intent.ACTION_SEND).apply {
|
||||||
data = Uri.parse("mailto:")
|
type = "text/plain"
|
||||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(CRASH_AND_FEEDBACK_EMAIL_ADDRESS))
|
putExtra(Intent.EXTRA_EMAIL, arrayOf(CRASH_AND_FEEDBACK_EMAIL_ADDRESS))
|
||||||
putExtra(Intent.EXTRA_SUBJECT, subject)
|
putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||||
val file = fileLogger.writeLogFile(
|
val file = fileLogger.writeLogFile(
|
||||||
this@ErrorActivity,
|
this@ErrorActivity,
|
||||||
activityKiwixErrorBinding?.allowLogs?.isChecked == true
|
activityKiwixErrorBinding?.allowLogs?.isChecked == true
|
||||||
)
|
)
|
||||||
putExtra(Intent.EXTRA_TEXT, "$emailBody\n\nDevice Logs:\n$${file.readText()}")
|
file.appendText(emailBody)
|
||||||
|
val path =
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
this@ErrorActivity,
|
||||||
|
applicationContext.packageName + ".fileprovider",
|
||||||
|
file
|
||||||
|
)
|
||||||
|
addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
putExtra(android.content.Intent.EXTRA_STREAM, path)
|
||||||
|
putExtra(Intent.EXTRA_TEXT, emailBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user