-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a crash handler to write logs in Download folder
- Loading branch information
1 parent
dbd3191
commit e688d75
Showing
4 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/info/plateaukao/einkbro/util/CustomExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package info.plateaukao.einkbro.util | ||
|
||
import android.os.Environment | ||
import java.io.File | ||
|
||
class CustomExceptionHandler(private val defaultHandler: Thread.UncaughtExceptionHandler) : | ||
Thread.UncaughtExceptionHandler { | ||
override fun uncaughtException(thread: Thread, throwable: Throwable) { | ||
val tempFile = File( | ||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/crash_log.txt" | ||
) | ||
if (tempFile.exists()) { | ||
tempFile.delete() | ||
} | ||
tempFile.createNewFile() | ||
tempFile.appendText(throwable.stackTraceToString()) | ||
|
||
defaultHandler.uncaughtException(thread, throwable) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters