German App Dienst funktioniert nach 1-2 Tagen nicht mehr

libero2022

New Member
Hallo vielleicht kann mir jemand auf die Sprünge helfen.

Ich habe eine App geschrieben, wenn eine SMS kommt wird eine E-Mail gesendet.
Funktioniert soweit gut, aber nach 1-2 Tage wird die App gestoppt.
Als Codebasis habe ich mich an die Infos im Forum gehalten.

Manifest Editor:
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(s1,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)

SetServiceAttribute(s1, android:foregroundServiceType, "location")


s1 Service:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type Message (Address As String, Body As String)
    Private nid As Int = 1
    nid = -1
End Sub

Sub Service_Create
    Service.StartForeground(nid, CreateNotification("gestartet" & "..."))
End Sub

Sub Service_Start (StartingIntent As Intent)

    If StartingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
        Dim messages() As Message
        messages = ParseSmsIntent(StartingIntent)
        For i = 0 To messages.Length - 1
            Log(messages(i))
        Next

        Service.StartForeground(nid, CreateNotification(messages(0).Body & "..."))
    
    End If
    Sleep(0)
    
     ' Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

Sub Service_Destroy

End Sub

Sub CreateNotification (Body As String) As Notification
    Dim notification As Notification
    notification.Initialize2(notification.IMPORTANCE_LOW)
    notification.Icon = "trayicon"

    notification.SetInfo("SMS Forwarder", Body, Main)
    Return notification
End Sub

' Parses an SMS intent And returns an Array of messages
Sub ParseSmsIntent (in As Intent) As Message()
    Dim messages() As Message
    If in.HasExtra("pdus") = False Then Return messages
    Dim pdus() As Object
    Dim r As Reflector
    pdus = in.GetExtra("pdus")
    If pdus.Length > 0 Then
        Dim messages(pdus.Length) As Message
        For i = 0 To pdus.Length - 1
            r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
            Array As Object(pdus(i)), Array As String("[B"))
            messages(i).Body = r.RunMethod("getMessageBody")
            messages(i).Address = r.RunMethod("getOriginatingAddress")
        Next
    End If
    sendemail(messages)
    Return messages
End Sub

Sub sendemail(message() As Message )
    Dim mail As SMTP
    mail.Initialize("g^host.mailserver.com", 465, "[email protected]", "meinpasswort", "SMTP")
    Dim Body As String
    Dim Subj As String
    Dim EmailTo As String
        
    Subj="Nachricht vom  Smartphone"
    Body= "Weitergeleitete SMS Nachricht"
        
    EmailTo="[email protected]"
    mail.UseSSL = True
    ' mail.StartTLSMode = True
    mail.To.Add(EmailTo)
    mail.HtmlBody=True
    mail.Subject = Subj
    mail.Body = Body & "<br>" & message(0).Body & "<br>" & DateTime.Time(DateTime.Now)
    
    mail.Sender = "[email protected]"
    mail.Send
    Try
    Catch
        Log("SendEmail " & LastException)
    End Try
End Sub

Meine Frage gibt es eine Möglichkeit die APP 24/7 laufen zu lassen.
 

Alexander Stolte

Expert
Licensed User
Longtime User
Meine Frage gibt es eine Möglichkeit die APP 24/7 laufen zu lassen.
Schaue dir mal den thread an, da sind ein paar links, vielleicht hilft dir das ja.
 
Upvote 0
Top