Android Question [SOLVED]Receiver question

kohle

Active Member
Licensed User
Longtime User
Hi,
I have b4a project with a webview. I use excecteJavascript to call a function that gives me the time and date for the next notifcation.
I use StartServiceAtExact.
In the Sub Receiver_Receive I show the notification.
I call after the with CallSubDelayed(Main, "main_nextNotification") to get and set the next notification.
All works fine as long the app is running in the background or foreground.
When the app is not running the receiver is triggered but the action stays in the queue until the activity is started.

What I need is to start the app in the background without need of clicking on the notification so
I can trigger in the webview pagefinished event my javascript function.


I tried this code with an intent I found in the forum but it dont work :
B4X:
Private Sub B4XPage_appear

    Log("Appear JK")
    
    Dim NewIntent As Intent = B4XPages.GetNativeParent(Me).GetStartingIntent
    If PreviousIntent.IsInitialized = False Or PreviousIntent <> NewIntent Then
        PreviousIntent = NewIntent
        If NewIntent.HasExtra("page") Then
            B4XPages.ShowPage(NewIntent.GetExtra("page"))
        End If
    End If
    
End Sub



Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    
    
    Dim filename As String = "reminder.txt"
    Dim paraMap As Map
    Dim bax As clsBasic
    
    bax.Initialize
        
    If File.Exists(File.DirInternal, filename) Then
        Dim Link As String = File.ReadString(File.DirInternal, filename)
        Log("Received text: " & Link)
        
        ' Delete it so it doesn't process twice
        File.Delete(File.DirInternal, filename)

        paraMap.Initialize
        paraMap = bax.GetParametersList(Link)
    
        If paraMap.Size=0 Then
            Return
        End If
        
        
        
        ShowNotification(paraMap)
        
        
        If StartingIntent.IsInitialized Then
            Dim cs As CSBuilder
            cs.Initialize.Bold.Size(20).Append($"Action: ${StartingIntent.Action}"$).PopAll
            Log(cs)
            ToastMessageShow(cs, True)
            If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
                'B4XPages.ShowPage(StartingIntent.Action)
            Else
                Log("StartActivity")
                Dim in As Intent
                in.Initialize(in.ACTION_MAIN, "")
                in.SetComponent(Application.PackageName & "/.main")
                in.PutExtra("page", StartingIntent.Action)
                StartActivity(in)
            End If
        
        End If
        
        
'       
        
        
        
        
    
        
    End If
    
    
    
    
    
    
End Sub

Private Sub ShowNotification(ma As Map)
    
    
    
    Dim title As String
    Dim body As String
    Dim ti As String
    Dim da As String
    Dim id As String
    
    
    title = "Korgi"
    body=ma.Get("title")
    ti=ma.Get("time")
    da=ma.Get("date")
    id=ma.Get("id")
    
    'Kein Datum
    If da="null" Or da="" Then
        Return
    End If
    
    title = da & " " & ti
    
    Dim n As NB6
    Dim ic  As Bitmap
    ic = LoadBitmapResize(File.DirAssets, "icon160.png", 32dip, 32dip, False)
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(ic)
    n.Build(title, body, id, Main).Notify(id) 'It will be Main (or any other activity) instead of Me if called from a service.End Sub
    
    
    'CallSub(B4XPages.MainPage, "nextNotification")
    CallSubDelayed(Main, "main_nextNotification")
    
        
            
    
End Sub
 
Top