Android Question Android push notification (GCM) without

studio4

Member
Licensed User
Longtime User
Hello friends, I'm making a simple multiplayer game. I have worked in this project during 7 month, and it is very important for me.:(

Nowadays, I am using a table in mysql where I save turns and points of each player. On their devices I have a service that is continually making visits to this table to see if it the user has turns availables ... The problem is that the battery and consumption data is very large and it is not possible. On the other hand, the app works very well. :(

I've been testing "Android push notification (GCM)" (https://www.b4x.com/android/forum/t...ion-gcm-framework-and-tutorial.19226/#content) and the example of Erel works perfectly and I think it could be a very good solution.

However, I have the problem that I can not making reviews in the table where the turns are inserted and sending messages from the "Messages sending tool" tool (command line) proposed Erel manually.

Could you make a trigger in mysql that when you register an insert inside the table where I keep the turns, mysql does the same work that "Messages sending tool" (app java command line) tool. It is to say, send the message in automatic way?. I could make fields in the table (mysql) for example, player id (SenderId) without any problems.

I need when I insert a new message in my notification table of mysql, it will send automatically.

At this moment, I have to use the manual tools (cmd in the comand line) to send these messages.

Is there another solution to what I propose?
 
Last edited:

studio4

Member
Licensed User
Longtime User
You can use B4X push server instead of the desktop tool. As it is written in B4J you can customize it as needed.


Sorry, I always have worked with B4a and I do not kow how to use B4J, but it is not the problem because I want to learn.

In this way, I have installed the application + java + ... but I can not understand the code.

I have removed all the things that are in relation with IOS because my app is only for android.

But I do not know how I can connect with my table of the database of mysql and make my query to see if I have to send an notification to some device.

In addition, I have compiled this app in my mobile phone, but I have a question.... In order to that, My usuers have to install two applications for receiving notifications (my game (B4A) and this server application (B4J) ? and... in the config.txt file of the folder "b4x push server\B4X-PushServer\PushServer\Objects", I only change the AndroidApiKey parametre. It is ok?

Please, I need help. I have read a lot of pages about it, but I do not have the necessary resources to solve it. The majority of my game is done (in 7 months), but If I can not do it, all my work will be thrown in the trash.

Can you send me a simple example about it?. I think that may be is not very dificult for you, but it is impossible for me.

It is very simple:

I have a table called notification in mysql with a field (username).
I only want that when a registrer will be inserted into this table, the user which matches the username receives an notification or message.(I do not how to make it, it is the real problem.)

After that, In my code of B4A my application makes an connection and reads the rest of fields of serveral tables (It is done).

The method of Android push notification (GCM) works very well with my app but, I need to send the messages automatically based in my table of mysl, so, I can not use the desktop tool to send it.

This is the part of the code that I believe I have to use:



Please, Erel and friends. Help me. Thanks for your attention.
 

Attachments

  • example.zip
    12.2 KB · Views: 292
Last edited:
Upvote 0

studio4

Member
Licensed User
Longtime User
It is possible call to the file .jar of the "Messages sending tool " called "b4a_gcm.jar" from the trigger when my table updates?
How can I pass the parametres like username and message? I am trying it.. but doesn't work.

trigger.png
 
Upvote 0

studio4

Member
Licensed User
Longtime User
B4X Push Server replaces the PHP script + MySQL db. It runs on the server.

Thanks Erel, but...

What are the steps that I need to follow?... I am really lost.

Can you give me some example of this. I need replace Messages sending tool for some thing that let to me send messages automatically. Some example? I need your help please.
 
Upvote 0

studio4

Member
Licensed User
Longtime User
Erel, I know that I am very insistent but it is very important for my job.

In one hand, I have made an little app in B4J which gets the fields of mysql table. It is Ok to send the push notification and implement it in the B4J Push Server.

On the other hand, I am trying to follow all the steps that appear in this thread: https://www.b4x.com/android/forum/threads/b4x-push-server.48560/#content but I have a lot of errors.

I only need to send notification to android devices (not ios devices), and only send (not receive), because to received it I will used B4a in the client device (it works perfectly).

Actually I have the API key and the Sender Id ( I got it in the google developers page). But in the treath you speak about "iPushKeyStore / iPushKeystorePassword" (I can not get it because I will not use ios devices) and "PushServerPassword" (I have put the same serverpassword that appears in the server_password field in the sending messages tool configuration. Is it correct?).

In my config.txt I have changed only the APY Key.

In addition to that, I can observe a lot of code modules in the project. Will I need all? (only for send messages). When I compile in debug mode, in my project only works the main module and then, in the right side appears "server is listening on port: 51044". How send and notification?

Please, help me.

Here you have project, config.txt and logs (lot of errors). What is happening?
 

Attachments

  • config.txt
    552 bytes · Views: 273
  • TEST.zip
    12.5 KB · Views: 263
  • log.png
    log.png
    20.8 KB · Views: 227
Last edited:
Upvote 0

studio4

Member
Licensed User
Longtime User
There are no errors in these logs. These messages are always printed when the server is started.

You do not need to set the iOS related keys.
As written in the code there are two lines that you can comment to disable the iOS features.


Thanks for your help Erel, but... then, why I do not receive any notification in my device?
 
Last edited:
Upvote 0

studio4

Member
Licensed User
Longtime User
Are you using the B4A client from that thread (https://www.b4x.com/android/forum/threads/b4x-push-server.48560/#content) ?

Have you configured the client with the server ip address?

Is the relevant port open in the firewall?


Yes, I am using the B4A client form this thread. In addition to that, when I use Messages sending tool my cliente of B4A receive the data ok.

I do not use Ip addresses. Where I need put it? I thought that all were in relation to the username that you put in the B4A client when you make a registre.

In reference of the firewall, Where I need open it, in my server? The port that my B4J server uses is of the example (tutorial). I do not change it.

But, When I use the desktop tool with cmd, my device received notification perfectly.

Please, look... This is my client (B4A), my project Server(BJ4), my file config.txt..
 

Attachments

  • B4J PUSH SERVER.zip
    12.5 KB · Views: 215
  • CLIENT.zip
    173.8 KB · Views: 264
  • config.txt
    558 bytes · Views: 241
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no need to post all these files.

You need to understand how each of the solutions work.

PHP based solution: Android push notification (GCM) framework and tutorial
It uses three components:
1. PHP script that runs on a server. If you are using the default configuration then you are using our server (you will need to switch to a different server later).
2. Desktop sending tool.
3. B4A client

B4X Push Server solution:
1. The push server which handles both the device registrations and the message sending.
2. B4A client.

There is no relation between these two solutions.

During development you can run the push server on your PC. You need to configure the client to use the PC ip address and you need to open a firewall port.
 
Upvote 0

studio4

Member
Licensed User
Longtime User
There is no need to post all these files.

You need to understand how each of the solutions work.

PHP based solution: Android push notification (GCM) framework and tutorial
It uses three components:
1. PHP script that runs on a server. If you are using the default configuration then you are using our server (you will need to switch to a different server later).
2. Desktop sending tool.
3. B4A client

B4X Push Server solution:
1. The push server which handles both the device registrations and the message sending.
2. B4A client.

There is no relation between these two solutions.

During development you can run the push server on your PC. You need to configure the client to use the PC ip address and you need to open a firewall port.

Erel, Thanks again. I have the correct client version now, I have modified the ip address and open my firewall of my router, but... I can not understand it. When I compile B4J, nothing appears, nothing occurs...

Can you upload some example please? I do not kwon how can I registre the device from B4J Push server and send a notification to the B4A client.

Sorry... but It is very important for my job... I have read the tutorial a lot of times, but.... nothing.
 
Last edited:
Upvote 0

studio4

Member
Licensed User
Longtime User
Hello Erel,


Finally, I could do to work to B4A-PushClient and B4X-PushServer and my device receives the messages that I send from B4A-PushClient B4X-PushServer correctly using the explorer of my pc for it.. but I have 3 doubts:

1-. How can I know the specific token that is generated by B4A-PushClient? This token is saved in the variable called token of this code (below)? (Dim token AsString).


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("registration_id") Then
Dim token As String = Intent.GetExtra("registration_id")
Dim j As HttpJob
j.Initialize("j", Me)
j.PostString(Main.ServerUrl & "/devicetoken", "token=" & token & "&type=2")
End If
End Sub

2-. B4A Push client makes the token id the first time that the client open his b4a app, but... if I compile again this app, Does it makes other different token id?, or B4a client detects that his token id has been generated previously and does not generate it again?

3-. Finally, I am using this command to send my messages:

http://<server url>/send?password=<PushServerPassword>&text=Message to send

What is the correct command to send a message to a specific user (only one user)? I imagine that I need to know his token id.

Yours sincerely. I am waiting for your answer. Thanks for your help again.
 
Last edited:
Upvote 0
Top