崩溃时分享崩溃日志

pull/854/head
gedoor 4 years ago
parent 81a7640ef9
commit 1b46f864b2
  1. 19
      app/src/main/java/io/legado/app/help/CrashHandler.kt

@ -4,12 +4,11 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import io.legado.app.service.help.ReadAloud
import io.legado.app.utils.FileUtils
import io.legado.app.utils.msg
import io.legado.app.utils.share
import java.io.PrintWriter
import java.io.StringWriter
import java.text.SimpleDateFormat
@ -64,18 +63,12 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
//添加自定义信息
addCustomInfo()
kotlin.runCatching {
//使用Toast来显示异常信息
Handler(Looper.getMainLooper()).post {
Toast.makeText(
context,
ex.message,
Toast.LENGTH_LONG
).show()
}
}
//分享崩溃日志
context.share(ex.msg, "崩溃日志")
//保存日志文件
saveCrashInfo2File(ex)
}
}
/**
* 收集设备参数信息
@ -116,7 +109,6 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
* 保存错误信息到文件中
*/
private fun saveCrashInfo2File(ex: Throwable) {
kotlin.runCatching {
val sb = StringBuilder()
for ((key, value) in paramsMap) {
sb.append(key).append("=").append(value).append("\n")
@ -146,6 +138,5 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler {
.writeText(sb.toString())
}
}
}
}

Loading…
Cancel
Save