Android Question Disable notifications with CheckBox

Isac

Active Member
Licensed User
Longtime User
Hi

I need to disable notifications when I press on a CheckBox1

Module Main

B4X:
Sub CheckBox1_CheckedChange(Checked As Boolean)
    Log(Checked)
End Sub


I would like to check the arrival of the message through Checked but I can not recover it,
how could I do?
thank you


Service FirebaseMessaging

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ID ${Message.MessageId}, Data ${Message.GetData}"$)
    Log("Message="& Message)
    Dim map As Map :map.Initialize
    map = CreateMap("body2":Message.GetData.Get("body"),"title1":Message.GetData.Get("title"))
    For Each key As String In map.Keys
    Dim value As String = map.Get(key)
    Log($"${key}:${value}"$)
    Next

    If CallSub2(Main,"CheckBox1_CheckedChange",Message)=True Then '<------------------

     'message does not arrive                    '<------------------
    Else         '<------------------
    Dim jgen As JSONGenerator
    jgen.Initialize(map)
    Dim n As NB6
    mano = LoadBitmapResize(File.DirAssets, "mano.png", 24dip, 24dip, False)
    n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(mano)
    n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString, Main).Notify(4)
End If
End Sub
 

Semen Matusovskiy

Well-Known Member
Licensed User
In activity (Main), where checkbox is placed:
1) add Process Global variable, let's say Public booleanDisablePushNotifications As Boolean.
2) In place, where you load/create layout, add CheckBox1.Checked = booleanDisablePushNotifications
3) In CheckBox1_CheckedChange event booleanDisablePushNotifications = Checked.

In fm_MessageArrived add to the top following check: If Main.booleanDisablePushNotifications Then Return
 
Last edited:
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
The best place for this variable is the "Starter" service:

B4X:
'Starter service
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public notifications As Boolean
End Sub

B4X:
'In module Main:
Sub CheckBox1_CheckedChange (Checked As Boolean)
   Starter.notifications=checked
End Sub

B4X:
'Firebase Service
If  Starter.notifications=True Then 
     'Do notifications
Else 
    ....
End if
 
Upvote 0
Top