Android Question Question about push notification on mysql

Douglas Farias

Expert
Licensed User
Longtime User
hi i and good morning
i m trying to make a push service based on my mysql conection

i make to service check 1 - 1 hour if have new news on my db
if have on db and user dont have on phone show a new push

but i m beginner in push notifications
i dont know this is correct or no

i tested on moto g but push works with app opned
and 5 or 10 minutes later

but last 10 minutes it dont work

in my main i start the service when app is Activity_Create

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'INICIA SERVIÇO DE NOTIFICAÇÕES
    StartService(notifica)

here is the code
B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Private kv As KeyValueStore
    Dim Notification1 As Notification
    Dim resultadocash = "resultadocash" As String
    Dim tempo As Timer
    Dim countdown As Int
    Dim fp As String
   
   
    Notification1.Initialize
    Notification1.Icon = "noti"
    Notification1.Vibrate = True
    Notification1.Sound = True
    Notification1.AutoCancel = True
    Notification1.Light = True
    Dim lala As Int
    Dim id, notificacao As String

End Sub
Sub Service_Create
    tempo.Initialize("Timer", 1000)
    countdown = 0
    If File.Exists(File.DirDefaultExternal, "achouganhou" ) = False Then
    Else
    fp = File.Combine(File.DirDefaultExternal,"achouganhou")
    End If
    kv.Initialize(fp, "data")   


End Sub

Sub Timer_Tick
    countdown = countdown + 1
    If countdown = 3600 Then
   
    If kv.ContainsKey("Notificacao") = True Then
        lala = kv.GetSimple("Notificacao")
        lala = lala + 1
        Log(lala)
        conferecash
    Else
        lala = 1
        conferecash
    End If
    countdown = 0
    End If
End Sub

Sub Service_Start (StartingIntent As Intent)
    tempo.Enabled = True
End Sub

    Sub ExecuteRemoteQuery(query As String, JobName As String)
        Dim jobs As HttpJob
        jobs.Initialize(JobName, Me)
        jobs.PostString("http://www.clickfight.com.br/query.php", query)
    End Sub
   
    Sub conferecash
    ExecuteRemoteQuery("SELECT * FROM notificacao WHERE Id = '"&lala&"' " , resultadocash)
    End Sub
   
   
   
    Sub JobDone (Job As HttpJob)
    If Job.Success Then
    Dim respostadoservidor As String
    respostadoservidor = Job.GetString

    Select Job.JobName
       
    Case "resultadocash"
    If respostadoservidor = "[]" Then
    Return
    End If
   
   
        Dim listaface As List
        Dim parserface As JSONParser
        Dim mface As Map

       
        If kv.ContainsKey("Notificacao") = True Then
       
            mface.Initialize
            parserface.Initialize(respostadoservidor)
            listaface.Initialize
       
            listaface = parserface.NextArray
            mface = listaface.Get(0)
           
            id = mface.Get("Id")
            notificacao = mface.Get("Notificacao")
           
                If kv.GetSimple("Notificacao") = id Then
                Return
                Else
                    kv.PutSimple("Notificacao",id)
                   
                End If

    Else
       
       
        Dim listaface2 As List
        Dim parserface2 As JSONParser
        Dim mface2 As Map
       
       
        mface2.Initialize
        parserface2.Initialize(respostadoservidor)
        listaface2.Initialize
   
        listaface2 = parserface2.NextArray
        mface2 = listaface2.Get(0)
       
        id = mface2.Get("Id")
        notificacao = mface2.Get("Notificacao")
        kv.PutSimple("Notificacao",id)
       
    End If

    End Select   
   

    Else
        Return
    End If
       
        Notification1.SetInfo("Achou Ganhou", notificacao, Main)
        Notification1.Notify(1)
        Service.StartForeground(1, Notification1)
       
    Job.Release
    End Sub
   

   

Sub Service_Destroy

End Sub
 
Top