11package eu.fliegendewurst.triliumdroid.util
22
3+ import android.app.ActivityManager
34import android.content.Context
45import android.content.Intent
56import android.net.Uri
@@ -14,6 +15,7 @@ import java.io.File
1415import java.io.FileOutputStream
1516import java.io.IOException
1617import java.io.InputStreamReader
18+ import java.util.*
1719
1820
1921object CrashReport {
@@ -31,7 +33,9 @@ object CrashReport {
3133 var bytes = " \n\n "
3234 bytes + = " Thread: ${thread.name} (ID = ${thread.id} )\n "
3335 bytes + = " Error: ${throwable} \n "
34- bytes + = " API Level: ${Build .VERSION .SDK_INT } (${Build .VERSION .RELEASE } )\n "
36+ bytes + = " API Level: ${Build .VERSION .SDK_INT } (Android ${Build .VERSION .RELEASE } )\n "
37+ bytes + = " RAM: ${getMemorySize(context) / 1024 / 1024 } MB\n "
38+ bytes + = " Locale: ${Locale .getDefault().language} \n "
3539 bytes + = " Stacktrace:\n "
3640 bytes + = throwable.stackTraceToString()
3741 fos.write(bytes.encodeToByteArray())
@@ -121,4 +125,15 @@ object CrashReport {
121125 .show()
122126 }
123127 }
128+
129+ private fun getMemorySize (context : Context ): Long {
130+ try {
131+ val actManager = context.getSystemService(Context .ACTIVITY_SERVICE ) as ActivityManager
132+ val memInfo = ActivityManager .MemoryInfo ()
133+ actManager.getMemoryInfo(memInfo)
134+ return memInfo.totalMem
135+ } catch (_: Exception ) {
136+ return 0
137+ }
138+ }
124139}
0 commit comments