#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Dim aktuelleActivity As Object 'CrashTakeScreenShot
Private logs As StringBuilder
Private logcat As LogCat
Private const emailAddress As String = "[email protected]" '####################### geht nur, wenn im Release Modus debug #######################
End Sub
Sub Service_Create
logs.Initialize
#if RELEASE
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
#end if
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
If logs.Length > 5000 Then
logs.Remove(0, logs.Length - 4000)
End If
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
'wait for 500ms to allow the logs to be updated.
Dim jo As JavaObject
Dim l As Long = 500
jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
logcat.LogCatStop
logs.Append(StackTrace)
LogWrite(logs)
SendEMail
Return True
End Sub
Sub Service_Destroy
End Sub
Sub LogWrite(Eventslog As String)
Dim TextWriter2 As TextWriter
Dim sdRoot As String
Dim now As Long
now = DateTime.now
sdRoot = File.DirRootExternal & "/"
If File.Exists(File.DirRootExternal, "crashlog.txt") = True Then
File.Delete(File.DirRootExternal, "crashlog.txt")
End If
Optionen.LoadOptionen
DateTime.DateFormat = "dd.MM.yyyy HH:mm"
File.WriteString(File.DirRootExternal, "crashlog.txt", "")
TextWriter2.Initialize(File.OpenOutput(sdRoot, "crashlog.txt", True))
TextWriter2.WriteLine("***************************" & CRLF & _
Application.VersionName & Application.VersionCode & CRLF & _
"apk_datum: " & Optionen.mapk_datum & CRLF & _
"Crash Datum: " & DateTime.Date(now) & CRLF & _
"Combera ID: " & HDB.mCombera_ID & CRLF & _
"***************************" & CRLF & _
CRLF & now & CRLF & "- " & Eventslog & CRLF)
TextWriter2.Close
' Log( Application.VersionCode) '40
' Log( Application.VersionName) 'cp
End Sub
Sub SendEMail
Dim email As Email
Dim filename As String = CallSub(aktuelleActivity,"MakeScreenshot") 'CrashTakeScreenShot
Optionen.LoadOptionen
email.To.Add(emailAddress)
email.Subject = "Programm-Fehler: " & Main.mActionName & ", " & Optionen.mgebiet_intern & ", " & Optionen.mvorname & " " & Optionen.mnachname
email.Body = "Fehler Text in der Anlage." & Chr(13) & "Der Fehler wird an COMBERA gesendet."
email.Attachments.Add(File.Combine(File.DirRootExternal, "crashlog.txt"))
email.Attachments.Add(filename) 'CrashTakeScreenShot
StartActivity(email.GetIntent)
End Sub