1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Crash report via HTTP

Discussion in 'Android Questions' started by marcick, Jul 12, 2019.

  1. marcick

    marcick Well-Known Member Licensed User

    Hi everybody,
    I want to capture a CrashLog in the starter service as described here and it works fine if I start the intent to send it by email.
    But if I try an HTTP post to silent send it to my server nothing is sent (I suppose the app terminate before the post is executed). Also I see I can't use Wait For after the post.
    This is my code. Any suggestion ?
    P.S. I've already implemented and worked with CrashLytics but I don't like it too much. Managing the reports in my server would be more efficient.

    Code:
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Dim jo As JavaObject
        
    Dim l As Long = 500
        jo.InitializeStatic(
    "java.lang.Thread").RunMethod("sleep"Array(l))
        
    logcat.LogCatStop
        CrashLog.Append(StackTrace)
        CrashLog.Append(
    CRLF & CRLF & "Crashreport created " & DateTime.Date(DateTime.Now))
        
    Dim ll As Map
        ll.Initialize
        ll.Put(
    "DeviceID",Main.DeviceID)
        ll.Put(
    "Type""AND")
        ll.Put(
    "Manufacturer",Main.DeviceManufacturer)
        ll.Put(
    "Model", Main.DeviceModel)
        ll.Put(
    "Log",CrashLog)
        
    Dim j As HttpJob
        j.Initialize(
    "j", Me)
        
    Dim pm As PackageManager
        
    Dim Reflector1 As Reflector
        ll.Put(
    "ApiLevel", Reflector1.GetStaticField("android.os.Build$VERSION""SDK_INT"))
        
    Dim ps As String="clientid=" & Main.DeviceID  _
        &  
    "&type=2" & "&msgtype=CrashReport" & "&cmdbody=" & MySub.MapToString(ll) & "&apilevel=" & Reflector1.GetStaticField("android.os.Build$VERSION""SDK_INT")
        j.PostString (
    "http://" & MySub.EBServerAddress & ":" & MySub.EBServerPort & "/devicecommand", ps)
        
    Return True
    End Sub
     
  2. sorex

    sorex Expert Licensed User

    I guess Return False will solve it as the app won't be closed and the http request won't be killed.
     
  3. marcick

    marcick Well-Known Member Licensed User

    You're right, thanks, but there are 2 problems:

    1) better the app crash so the user feels like something is not working correctly, instead (return false) silently continue the app
    2) if the post exceed the limit of 4K it is truncated and does not arrive to destination
     
  4. sorex

    sorex Expert Licensed User

    1. you can always use an application exit in the http request completed event (or use wait for) and then exit.

    2. could be post limits on the server end or something else. the most relavent part is at the beginning of the text, not? you could strip it down with substring2(0,4000)
     
    marcick likes this.
  5. marcick

    marcick Well-Known Member Licensed User

    Looks like there is some problem with Wait For in the Application_Error sub, but with the classic sub JobDone it works.
    Great !
    Thanks a lot
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice