B4A Library Google Cloud Messaging Server\Visual Studio

Hello All, i'm not sure if this will be of any help to anyone, but i decided to share it with everyone here anyway. I'm writing an application for a client and needed an easy way to test out a portion of the app which requires the Google Cloud Messaging system, so after searching for a while for an easy way for me to do it, i decided to write this application in Visual Basic 2008, Erel's tool in his Tutorial is a great tool but i just don't like the fact that i had to open a command window every time and type in the command to send a message.

Anyhow with this tool you only need to type the API Key provided by google once, along with the Sender ID which is the number provided when you log in into your Google API, and the Registration ID, you get this when you run your application.

This is the application written in Visual Studio 2008
GCM_Server.png Message.jpg

the SenderID is this number you receive from google
SenderID.jpg

Your Api Key you get it from here
api.jpg

Your Registration ID is the number generated when you run your application
check Erel's tutorial for this
http://www.b4x.com/forum/basic4android-getting-started-tutorials/19226-android-push-notification-gcm-framework-tutorial.html#post110713

Again once you enter all this information for the first time on the required fields, this information gets saved into a config.txt file the next time you launch the VB GCM server it will load the saved api, senderId and registration id information.

Hope you guys find this useful!
View attachment GCM_Server executable.zip

And Here's the source code, please feel free to play with it, if anyone expands the functionality of it please don't forget to post your changes on this thread, so that others can benefit from this as well!
View attachment GCM_Server_Source_code.zip


Cheers!
 
Last edited:

dibesw

Active Member
Licensed User
Longtime User
HI,
I tried push notification.
I have registred a name from this app.
Then when I run b4a_gcm.bat thats works well.
This is the .bat:
D:\Utility\PocketPC\ANDROID\NotificheOK\Desktop\b4a_gcm.bat send pillone "TEST COLLEGAMENTO POCKET"

However when I run your VB2008 application don't works. Why?
Thanks.

pillone1.jpg
 

walterf25

Expert
Licensed User
Longtime User
HI,
I tried push notification.
I have registred a name from this app.
Then when I run b4a_gcm.bat thats works well.
This is the .bat:
D:\Utility\PocketPC\ANDROID\NotificheOK\Desktop\b4a_gcm.bat send pillone "TEST COLLEGAMENTO POCKET"

However when I run your VB2008 application don't works. Why?
Thanks.

pillone1.jpg
Please read the first post, the registration ID is the number you get when you restiger your app, in the register service.
 

dibesw

Active Member
Licensed User
Longtime User
Thank you walter,
but I have a bad english.
I understood that:
"Your Registration ID is the number generated when you run your application"
but when I run Erel PushExample, where is this RegistrationID?
I can not find it and then the app not return it.
 

walterf25

Expert
Licensed User
Longtime User

dibesw

Active Member
Licensed User
Longtime User
OK walter, problem is that I don't know how read
the registration id from PushService.
Main app call PushService, but how can I get this ID when PushService ends?
Control does not return to main at the PushService ends.
Excuse for my english.
 

walterf25

Expert
Licensed User
Longtime User
OK walter, problem is that I don't know how read
the registration id from PushService.
Main app call PushService, but how can I get this ID when PushService ends?
Control does not return to main at the PushService ends.
Excuse for my english.
Ok, if you go to the module named PushService, you will a subroutine called "Sub HandleRegistrationResult"
in that sub you will see a line like this "Else If Intent.HasExtra("registration_id") Then"
you need to add this line so you can see the registration ID in the filtered logs.
Log("rid " & rid)
just take a look at the whole code here:
B4X:
Sub HandleRegistrationResult(Intent As Intent)
    If Intent.HasExtra("error") Then
        Log("Error: " & Intent.GetExtra("error"))
        ToastMessageShow("Error: " & Intent.GetExtra("error"), True)
    Else If Intent.HasExtra("unregistered") Then
        If hcInit = False Then hc.Initialize("hc")
        Dim req As HttpRequest
        req.InitializeGet(Main.BoardUrl & "?device_password=" & Main.DeviceBoardPassword & _
            "&name=" & Main.DeviceName & "&id=") 'Empty id is sent here. This will cause the board to delete this name.
        hc.Execute(req, UnregisterTask)
    Else If Intent.HasExtra("registration_id") Then
        If hcInit = False Then hc.Initialize("hc")
        Dim rid As String
        rid = Intent.GetExtra("registration_id")
        Log("rid " & rid)   ' this is the line that will log the registration ID on the filtered logs.
        Dim req As HttpRequest
        req.InitializeGet(Main.BoardUrl & "?device_password=" & Main.DeviceBoardPassword & _
            "&name=" & Main.DeviceName & "&id=" & rid)
        hc.Execute(req, RegisterTask)
    End If
End Sub
 

dibesw

Active Member
Licensed User
Longtime User
OK walter, I solved all.
But when i run GCM_server executable, program give an error:

pillone2.jpg


with GCM source code, with THE SAME CONFIG, all works well!
Thank you for all...
 

sigster

Active Member
Licensed User
Longtime User
Hi

Thanks for your app I can use it but I can not retrieves characters like ö ð þ æ
do you know how I can fix it

is this service total free or are limits :)

Regards
Sigster
 

Douglas Farias

Expert
Licensed User
Longtime User
why give me this error
Error=MismatchSenderId
collapse_key=nethouse&time_to_live=108&delay_while_idle=1&data.message=Fala Rapaz!!&data.time=24/6/2014

my Project Number: 152183912140
 

walterf25

Expert
Licensed User
Longtime User
why give me this error


my Project Number: 152183912140
I don't think you are configuring everything right, please see the first post and follow every instruction.

Thanks,
Walter
 

Jose Luis Barajas

Member
Licensed User
Longtime User
Hellow Walterf25

I was reading your post with to great detail. I don't understand why your program need the registration id.
If I want send a push message to any client, I don't know the registration Id, also I don't know the input user name captured in the device app.
I need to store this values in the server for send push messages?

Sorry for my english!
 
Top