mirror of
https://github.com/dzeiocom/OpenHealth.git
synced 2025-04-23 11:22:10 +00:00
feat: Add Error handling
This commit is contained in:
parent
375bad46a7
commit
a31d85b1fb
@ -44,6 +44,10 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- Activity for error handling -->
|
||||||
|
<activity android:name=".ui.ErrorActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.OpenHealthService"
|
android:name=".services.OpenHealthService"
|
||||||
android:permission="android.permission.ACTIVITY_RECOGNITION" />
|
android:permission="android.permission.ACTIVITY_RECOGNITION" />
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.dzeio.openhealth
|
package com.dzeio.openhealth
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.util.Log
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.dzeio.openhealth.ui.ErrorActivity
|
||||||
import com.google.android.material.color.DynamicColors
|
import com.google.android.material.color.DynamicColors
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -16,6 +19,21 @@ class Application : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
|
// Application Error Handling
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler { paramThread, paramThrowable ->
|
||||||
|
//Log error to logcat if it wasn't done before
|
||||||
|
Log.e(TAG, "Error, ${paramThread.id}", paramThrowable)
|
||||||
|
|
||||||
|
// send use to the Error Activity
|
||||||
|
val intent = Intent(applicationContext, ErrorActivity::class.java)
|
||||||
|
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
intent.putExtra("error", paramThrowable.stackTraceToString())
|
||||||
|
startActivity(intent)
|
||||||
|
|
||||||
|
return@setDefaultUncaughtExceptionHandler
|
||||||
|
}
|
||||||
|
|
||||||
// Android Dynamics Colors
|
// Android Dynamics Colors
|
||||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||||
|
|
||||||
|
90
app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt
Normal file
90
app/src/main/java/com/dzeio/openhealth/ui/ErrorActivity.kt
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package com.dzeio.openhealth.ui
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.dzeio.openhealth.Application
|
||||||
|
import com.dzeio.openhealth.BuildConfig
|
||||||
|
import com.dzeio.openhealth.core.BaseActivity
|
||||||
|
import com.dzeio.openhealth.databinding.ActivityErrorBinding
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class ErrorActivity : BaseActivity<ActivityErrorBinding>() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "${Application.TAG}/ErrorActivity"
|
||||||
|
}
|
||||||
|
|
||||||
|
override val bindingInflater: (LayoutInflater) -> ActivityErrorBinding =
|
||||||
|
ActivityErrorBinding::inflate
|
||||||
|
|
||||||
|
override fun onCreated(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreated(savedInstanceState)
|
||||||
|
|
||||||
|
val params = intent
|
||||||
|
|
||||||
|
val data = params.getStringExtra("error")
|
||||||
|
|
||||||
|
// Get Application datas
|
||||||
|
val deviceToReport = if (Build.DEVICE.contains(Build.MANUFACTURER)) Build.DEVICE else "${Build.MANUFACTURER} ${Build.DEVICE}"
|
||||||
|
|
||||||
|
val infos = """
|
||||||
|
Application ID: ${BuildConfig.APPLICATION_ID}
|
||||||
|
Version Code: ${BuildConfig.VERSION_CODE}
|
||||||
|
Version Name: ${BuildConfig.VERSION_NAME}
|
||||||
|
|
||||||
|
Android ${Build.VERSION.RELEASE} SDK ${Build.VERSION.SDK_INT}
|
||||||
|
Model: $deviceToReport ${Build.MODEL}
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
// merge our texts
|
||||||
|
val reportText = infos + "\n\n" + data
|
||||||
|
|
||||||
|
// put it in the textView
|
||||||
|
binding.errorText.text = reportText
|
||||||
|
|
||||||
|
// Handle the Quit button
|
||||||
|
binding.errorQuit.setOnClickListener {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the Email Button
|
||||||
|
binding.errorSubmitEmail.setOnClickListener {
|
||||||
|
|
||||||
|
// Create Intent
|
||||||
|
val intent = Intent(Intent.ACTION_SEND)
|
||||||
|
intent.data = Uri.parse("mailto:")
|
||||||
|
intent.type = "text/plain"
|
||||||
|
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("report.openhealth@dzeio.com"))
|
||||||
|
intent.putExtra(Intent.EXTRA_SUBJECT, "Error report for application crash")
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, "Send Report Email\n$reportText")
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivity(Intent.createChooser(intent, "Send Report Email..."))
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(this, "Not Email client found :(", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the GitHub Button
|
||||||
|
binding.errorSubmitGithub.setOnClickListener {
|
||||||
|
|
||||||
|
// Build URL
|
||||||
|
val url = "https://github.com/dzeiocom/OpenHealth/issues/new?title=Application Error&body=$reportText"
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivity(
|
||||||
|
Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||||
|
)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(this, "No Web Browser found :(", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
80
app/src/main/res/layout/activity_error.xml
Normal file
80
app/src/main/res/layout/activity_error.xml
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
|
||||||
|
android:id="@+id/linearLayout2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView3"
|
||||||
|
style="?textAppearanceHeadline5"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/error_app_crash"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView4"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/error_app_report"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView2"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/error_submit_email"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textView4">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/error_text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
style="?textAppearanceCaption"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/error_submit_github"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/report_github"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
app:layout_constraintBaseline_toBaselineOf="@+id/error_submit_email"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/error_submit_email"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:text="@string/report_email"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/error_quit"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/error_quit"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:text="@string/quit"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -39,5 +39,12 @@
|
|||||||
<string name="edit_goal">Modifier l\'objectif</string>
|
<string name="edit_goal">Modifier l\'objectif</string>
|
||||||
<string name="edit_daily_goal">Modifier le but journalier</string>
|
<string name="edit_daily_goal">Modifier le but journalier</string>
|
||||||
<string name="permission_declined">Vous avez décliné une permission, vous ne pouvez pas utiliser cette extension suaf si vous réactivez la permission manuellement</string>
|
<string name="permission_declined">Vous avez décliné une permission, vous ne pouvez pas utiliser cette extension suaf si vous réactivez la permission manuellement</string>
|
||||||
|
<string name="menu_steps">Pas</string>
|
||||||
|
|
||||||
|
<!-- Error Activity Translations -->
|
||||||
|
<string name="error_app_crash">Une Erreur est survenu lors de l\'utilisation de l\'application</string>
|
||||||
|
<string name="error_app_report">Merci d\'envoyer le rapport d\'erreur afin que nous puissions améliorer votre experience</string>
|
||||||
|
<string name="report_email">Envoyer par Email</string>
|
||||||
|
<string name="report_github">Envoyer depuis Github</string>
|
||||||
|
<string name="quit">Quitter</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -51,4 +51,12 @@
|
|||||||
<string name="permission_declined">You declined a permission, you can\'t use this extension unless you enable it manually</string>
|
<string name="permission_declined">You declined a permission, you can\'t use this extension unless you enable it manually</string>
|
||||||
<string name="edit_daily_goal">Modifiy daily goal</string>
|
<string name="edit_daily_goal">Modifiy daily goal</string>
|
||||||
<string name="menu_steps">Steps</string>
|
<string name="menu_steps">Steps</string>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Error Activity Translations -->
|
||||||
|
<string name="error_app_crash">An Error Occurred in the application forcing it to close down</string>
|
||||||
|
<string name="error_app_report">Please report it so we can enhance you\'re Android OpenHealth experience</string>
|
||||||
|
<string name="report_github">Report on Github</string>
|
||||||
|
<string name="report_email">Report via Email</string>
|
||||||
|
<string name="quit">Quit</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user