Android Question GCM about idle mode to receive messages.

dragonguy

Active Member
Licensed User
Longtime User
i has write a small app to receive notification for my server when get new event.
server app send the json format string to gcm then gcm send to my device, but how can i receive the
messages when my phone idle, and if my phone switch off when i on the phone, phone can immediately receive the message.

i try many setting but my phone only can receive when my phone active, if phone become
idle and cant receive any messages.

server side set delay_while_idle:true.
if i set delay_while_idle:false, i can immediately receive the messages when phone idle but not at phone
off.

is it can make app can receive the message when idle or turn on the device can immediately receive the
message?
 

DonManfred

Expert
Licensed User
Longtime User
I believe that you dont get this message if your device is off and you have no way to get the notification later when device is on again.
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
According to Google documentation the message should be sent when the device is later connected when delay_while_idle is true.

Yes, I can receive the message when set delay_while_idle is true, but I want device immediately receive the message when idle or turn on. If Gcm can't do this for me, is it I can write a special code for server and client application to hold messages status, if client didn't return back status to server certain period, server will send a message again.
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
my main server application is written by vb.net, already implement with some features and gcm functions.
temporary i cannot change to use Custom WebSocket Based Push Framework.

i have a question about gcm, clients device is it can send messages to server? my server didn't have a registration id, so how can i send messages to server?
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
i still cannot send the message to server.
here is my code

B4X:
Sub send_online_status()

    Dim Job As HttpJob
    Job.Initialize("send message",Me)
    Job.PostString("https://android.googleapis.com/gcm/send","#Y#" & strUserEmail & "#")
    Job.GetRequest.SetHeader("Authorization","key=" & apikey)
   
End Sub

at JobDone return send successful, but server didn't receive ant message.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If you go through the gcm tutorial and got it working then you should have a database with the registration ids (it the table created in the php-script)... This php get called after registration from your app to google and also get the ID...
You need to fetch this database from your app to get the known IDs which you can use to send to GCM
 
Upvote 0

dragonguy

Active Member
Licensed User
Longtime User
here is the code from b4j, i add to my b4a project

B4X:
Sub btnSend_Action
    Dim keys As string = "xxxxxxxx" ' device registration id
    Dim apikey as string = "xxxxxxxx"
    Dim json As JSONGenerator
    Dim m As Map
    m.Initialize
    m.Put("registration_ids", keys)
    Dim data As Map
    data.Initialize
    data.Put("data", "Yes")
    'you can add more fields to data and then read them on the device.
    m.Put("data", data)
    json.Initialize(m)
    Dim job As HttpJob
    job.Initialize("send message", Me)
    job.PostString("https://android.googleapis.com/gcm/send", json.ToString)
    job.GetRequest.SetContentType("application/json")
    job.GetRequest.SetHeader("Authorization", "key=" & apikey)
End Sub

but this code is sent back message to my device not my server vb application, if i using smtp to send, server
can receive the message.
 
Last edited:
Upvote 0
Top