Java Question SOLVED onesignal library

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hi everyone! Is there a way to integrate onesignal with b4A? I am obliged to do so because I have to add an APP to an existing solution


regards
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Hi everyone! Is there a way to integrate onesignal with b4A?
Yes, write a wrapper for it.

Alternatrively you can JUST IGNORE the android library and USE the REST Api they provide!

To use the Rest API you only need to use okhttputils2. No wrapper needed... :cool:
 
Last edited:

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Excellent! use the REST API and it worked perfect! You only need this code and integrate with Firebase and voila, it works!

B4X:
Public Sub SubscribeToTopics

    fm.Initialize("fm")
    fm.SubscribeToTopic("XXXXX") 'you can subscribe to more topics
      Log (fm.Token)

    'correr el codigo POST
    
    Dim phone As Phone
    
    
    Dim jsonmapa As Map
    jsonmapa.Initialize
    jsonmapa.Put("app_id","XXXXXXXXXXXXXXXXXXXx") ' add ID APP onesignal
    jsonmapa.Put("identifier",fm.Token)
    jsonmapa.Put("language","es")
    jsonmapa.Put("timezone",DateTime.GetTimeZoneOffsetAt(DateTime.Now))
    jsonmapa.Put("gamer_version","1.0")
    jsonmapa.Put("device_os",phone.SdkVersion)
    jsonmapa.Put("device_type","1")
    jsonmapa.Put("device_model",phone.Model)
    Dim par As Map
    par.Initialize
    par.Put("clave","test") ' What you need
    jsonmapa.Put("tags",par)
    
    Dim json_generator As JSONGenerator
    
    json_generator.Initialize(jsonmapa)
    
    Dim Post As HttpJob
    Post.Initialize("Post", Me)
    Post.Poststring("https://onesignal.com/api/v1/players",json_generator.ToString)
    Post.GetRequest.SetContentType("application/json;charset=UTF-8")
    
End Sub

Sub jobDone(job As HttpJob)
   Log(job)
   If job.Success Then
   Log(job.GetString)
    
   Dim json_desc As JSONParser
   json_desc.Initialize(job.GetString)
   Dim resultado As Object 
   resultado = json_desc.NextObject
   Dim mapa As Map
   mapa.Initialize
   mapa = resultado
   Log(mapa.Get("id")) ' returns the token needed to send a notification from onesignal
    
  End If
job.Release
  
End Sub
 

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hi @gregorio_adrian_gimenez nice to meet you. I'm trying to use your solution when I should add the code that you have indicated above.
Hi, you have to integrate Firebase messaging.
https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/
You can use wherever you want. I add it in the FirebaseMessaging module

You can use wherever you want. I add it in the FirebaseMessaging module. Within the subscribetoTopics function, which is called from the starter Service module as soon as the application is opened.

1668548070641.png


Regards
 
Top