I use the example provided by goole and I built an client side application to get notifications and a server side, both applications (code) is those provided by google.
I run the application on the client side and I get the registration_id. some huge string, in this format which is below:
APA91bEgguwt98xLbivrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLxDalNoEktCSVbOkT0-uFH2FaRnfpkRME2tzuvr0BycMNEhX_Ix1PV_XXXXXXXXXXXXXXXXXXXXXN5hcseY_wA.
This proves me that the client application works. Now the server (java, google example):
public static void main(String[] args) {
Sender sender = new Sender("AIzaSXXXXXXXXXX_XXXXXXXXXXXXXXXrQOnoGZw");
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message",
"this text will be seen in notification bar!!")
.build();
try {
Result result = sender.send(message, "APA91bEgguwt98xLbivrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLxDalNoEktCSVbOkT0-uFH2FaRnfpkRME2tzuvr0BycMNEhX_Ix1PV_XXXXXXXXXXXXXXXXXXXXXN5hcseY_wA", 3);
System.out.println(result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This is the server. When I run the server I got as result something like this:
[ messageId=0:1341907115903155%921c249a00000031 ]
but no message on the client and I don't understand why. What is the meaning of the response I got from server? Is it the success response?
I need help to understand what is wrong?
Please review their comment
http://developer.android.com/guide/google/gcm/gcm.html
Note: If your organization has a firewall that restricts the traffic to or from the Internet, you'll need to configure it to allow connectivity with GCM. The ports to open are: 5228, 5229, and 5230. GCM typically only uses 5228, but it sometimes uses 5229 and 5230. GCM doesn't provide specific IPs. It changes IPs frequently.
According to the GCM Documentation:
When a 3rd-party server posts a message to GCM and receives a message ID back, it does not mean that the message was already delivered to the device. Rather, it means that it was accepted for delivery. What happens to the message after it is accepted depends on many factors.
In the best-case scenario, if the device is connected to GCM, the screen is on, and there are no throttling restrictions (see Throttling), the message will be delivered right away.
Remove your internet firewall if you are using it and try again
Please go through this
If your facing delay notification or message problem in GCM then try this solution.
I know this is not proper solution but it's WORKS Install this app it's really work for me HERE
Related
I am trying to create an Android chat client using ejabberd XMPP server (19.02), Smack library (4.2.4) and Android SDK 25 using Android Studio.
I followed the example app found here: https://www.blikoontech.com/tutorials/android-smack-xmpp-introductionbuilding-a-simple-client
All is working well and I can send messages between two different Android devices running that sample app.
In ejabberd, there are options to send messages to the clients directly from the server using a CLI tool called ejabberdctl or ejabberd REST API. When I sent messages that way, the Android client doesn’t receive those messages. I tried with other clients like Conversations and Gajim and they could all receive it. I am pretty sure messages sent using those methods arrived because they were received as offline messages (on ejabberd web admin) when sent to offline clients.
Here is the part of the Android (java) code (roosterconnection.java from that sample app) that is to receive incoming messages. Please suggest me if I am missing anything. Thanks a lot.
ChatManager.getInstanceFor(mConnection).addIncomingListener(new IncomingChatMessageListener() {
#Override
public void newIncomingMessage(EntityBareJid messageFrom, Message message, Chat chat) {
///ADDED
Log.d(TAG,"message.getBody() :"+message.getBody());
Log.d(TAG,"message.getFrom() :"+message.getFrom());
String from = message.getFrom().toString();
String contactJid="";
if ( from.contains("/"))
{
contactJid = from.split("/")[0];
Log.d(TAG,"The real jid is :" +contactJid);
Log.d(TAG,"The message is from :" +from);
}else
{
contactJid=from;
}
//Bundle up the intent and send the broadcast.
Intent intent = new Intent(RoosterConnectionService.NEW_MESSAGE);
intent.setPackage(mApplicationContext.getPackageName());
intent.putExtra(RoosterConnectionService.BUNDLE_FROM_JID,contactJid);
intent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY,message.getBody());
mApplicationContext.sendBroadcast(intent);
Log.d(TAG,"Received message from :"+contactJid+" broadcast sent.");
///ADDED
}
});
Here is a possible explanation, based in my experiments with a desktop client, Tkabber:
I login to ejabberd using Tkabber client, account user1#localhost, resource tka1, priority -3. The negative priority in this experiment is important.
Then I execute the command to send to full JID, including the correct resource:
ejabberdctl send_stanza aaa#localhost user1#localhost/tka1
"<message>..."
The client receives the stanza correctly.
Now I send to bare JID (without providing resource), and another setting another resource:
ejabberdctl send_stanza aaa#localhost user1#localhost
"<message>..."
ejabberdctl send_stanza aaa#localhost user1#localhost/sdsd
"<message>..."
In those cases, none of them are received by the client, because the resource doesn't match, and because its priority is negative. I can see those messages stored offline in the database.
In your client, maybe you have to add another call to set the presence online, with a positive priority.
We use GCM messaging to send remote commands to device. We have one particular client who uses the same model of devices from one manufacturer and with has 5.1 OS.
Our client registration process is pretty standard, that is once the client logs-in, it updates the GCM-Id to server and on server we have some commands that can be sent to the registered devices and internally it uses the registration id.
We are observing that even if the remote command is sent to one of the devices, it is being delivered to all these devices. The GCM Id on all these devices is different.
This does not happen with other devices (or we have not seen it yet)
If we use FCM Diagnostics and verify the lifecycle of message using the GCM-Ids of these devices we see that the same message ID has been delivered to all these devices.
We made sure that there is no ghost or random delivery from our backend, we verified backend logs and added extra logging as well.
Request for tips or hints, if anybody else saw such an issue earlier.
Try see this git on line 57, he uses json to sent a single message to multiples registration ids.
Example json content:
{
"data":
{
"from": "my_name",
"time": "0:56:23"
},
"registration_ids": ["id_1", "id_2", "id_3", "id_4"]
}
Lucas is correct in his example, the registration_ids is a parameter that specifies a list of devices (registration tokens, or IDs) receiving a multicast message. It can contain at least 1 and at most 1000 registration tokens.
Note: registration_ids are only for multicast messaging, not for
single recipients. Multicast messages (sending to more than 1
registration tokens) are allowed using HTTP JSON format only.
For more information, check this documentation.
I have a list of GCM registered users and their corresponding registration Ids in a database table, and I actually want to unregister a user whenever he/she is deleted from the table. I found a lot of examples here in Stackoverflow, but most of them are based on the old GCMRegistrar API which is now deprecated. I'm using GoogleCloudMessaging API and registering a user by following method:
private void registerUser(){
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
String regId = "";
try {
regId = gcm.register(getString(R.string.project_number));
Log.i("registrationId", regId);
}
catch (IOException e) {
Log.i("Registration Error", e.getMessage());
}
}
I have an administrator app, which acts as a 3rd-party application server, since it pushes notifications to all users. I want to unregister a specific user from this administrator app with following method:
private void unRegister(String regId) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getBaseContext());
try {
gcm.unregister();
}
catch (IOException e) {
System.out.println("Error Message: " + e.getMessage());
}
}
But it confuses me that unregister() method does not take registration Id as an argument, which makes it impossible to unregister a specific device. Is there any way to unregister a specific device from GCM by registration Id ?.
This method does the trick:
gcm.unregister();
However, gcm.unregister() is now deprecated, hence, you must use one of these:
InstanceID.deleteToken() or InstanceID.deleteInstanceID().
These methods take the following parameters:
public void deleteToken (String authorizedEntity, String scope)
Being authorized entity the entity that you want to remove...
// THE FOLLOWING EXPLANATION IS ONLY FOR "UNREGISTER"
So, based on your comment:
But it confuses me that unregister() method does not take registration
Id as an argument, which makes it impossible to unregister a specific
device.
That's because you are expecting it to work in a way that it doesn't. It seems like you want to be able to make an http request passing a parameter to uregister(e.g. "http://www.gcmserver.com?unregisterid=xxxx"), and that's not the way it works, this is the way it works based on Google's Documentation:
How unregistration works
An application can be automatically unregistered after it is
uninstalled from the device. However, this process does not happens
right away, as Android does not provide an uninstall callback. What
happens in this scenario is as follows:
The end user uninstalls the application.
The 3rd-party server sends a message to GCM server.
The GCM server sends the message to the device.
The GCM client receives the message and queries Package Manager about
whether there are broadcast receivers configured to receive it, which
returns false.
The GCM client informs the GCM server that the
application was uninstalled.
The GCM server marks the registration ID for deletion.
The 3rd-party server sends a message to GCM.
The GCM returns a NotRegistered error message to the 3rd-party server.
The 3rd-party deletes the registration ID.
So, based on that, what the method gcm.unregister() actually does is marking that device for deletion(think of it as forcing the first steps of the process without actually uninstalling the app), letting the server know that it no longer needs to get notifications, also by not taking an "Id" as a parameter it means that it is referencing to that specific device.
Regards!
unregister() is now deprecated:
https://developers.google.com/android/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#unregister()
Quoting the docs you should call:
Instead use InstanceID.deleteToken() or InstanceID.deleteInstanceID().
I am attempting to run gcm server using node-xmpp, but xmpp client does not seem to open at all and closes after timeout.
var xmpp = require('node-xmpp-client');
var options = {
type: 'client',
jid: 'fake-project-123#gcm.googleapis.com',
password: 'ApiKeyHere',
port: 5235,
host: 'gcm.googleapis.com',
legacySSL: true,
preferredSaslMechanism : 'PLAIN'
};
console.log("Creating XMPP Application");
var cl = new xmpp.Client(options);
cl.on('online', function()
{
console.log("XMPP Online");
});
Rest of the code was omitted. In the console, I never get to see "XMPP Online".
How do I check if xmpp is even connecting, and where it fails to open?
I got the same problem and found out that the Connection.startStream() was never called, although the socket was opened successfully.
Here's my pull request:
https://github.com/node-xmpp/node-xmpp-client/pull/61
Until it gets merged, you can use my fork, which should work for GCM:
https://github.com/Riplexus/node-xmpp-client
I followed this from gcm google groups and it worked for me.
And for timeouts you can try
xmppClient.connection.socket.setTimeout(0)
xmppClient.connection.socket.setKeepAlive(true, 10000)
Don't forget to whitelist your server ip in google console.
I have given up the hope of using node-xmpp and game smack client a try. Sadly it did not work, but I did get an error saying my project is not whitelisted. When project is whitelisted, it can receive messages from android devices, which is exactly what I need and is the sole reason why I went straight to CCS (XMPP). Without the whitelist, it is not possible to use CCS (XMPP) for sending the messages to android devices. In order to use HTTP method, the project does not need to be whitelisted, but has a limitation to being able to send messages only. I have signed up upstream GCM but have yet to receive response.
https://services.google.com/fb/forms/gcm/
I use the example provided by goole and I built an client side application to get notifications and a server side, both applications (code) is those provided by google.
I run the application on the client side and I get the registration_id. some huge string, in this format which is below:
APA91bEgguwt98xLbivrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLxDalNoEktCSVbOkT0-uFH2FaRnfpkRME2tzuvr0BycMNEhX_Ix1PV_XXXXXXXXXXXXXXXXXXXXXN5hcseY_wA.
This proves me that the client application works. Now the server (java, google example):
public static void main(String[] args) {
Sender sender = new Sender("AIzaSXXXXXXXXXX_XXXXXXXXXXXXXXXrQOnoGZw");
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message",
"this text will be seen in notification bar!!")
.build();
try {
Result result = sender.send(message, "APA91bEgguwt98xLbivrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLxDalNoEktCSVbOkT0-uFH2FaRnfpkRME2tzuvr0BycMNEhX_Ix1PV_XXXXXXXXXXXXXXXXXXXXXN5hcseY_wA", 3);
System.out.println(result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This is the server. When I run the server I got as result something like this:
[ messageId=0:1341907115903155%921c249a00000031 ]
but no message on the client and I don't understand why. What is the meaning of the response I got from server? Is it the success response?
I need help to understand what is wrong?
Please review their comment
http://developer.android.com/guide/google/gcm/gcm.html
Note: If your organization has a firewall that restricts the traffic to or from the Internet, you'll need to configure it to allow connectivity with GCM. The ports to open are: 5228, 5229, and 5230. GCM typically only uses 5228, but it sometimes uses 5229 and 5230. GCM doesn't provide specific IPs. It changes IPs frequently.
According to the GCM Documentation:
When a 3rd-party server posts a message to GCM and receives a message ID back, it does not mean that the message was already delivered to the device. Rather, it means that it was accepted for delivery. What happens to the message after it is accepted depends on many factors.
In the best-case scenario, if the device is connected to GCM, the screen is on, and there are no throttling restrictions (see Throttling), the message will be delivered right away.
Remove your internet firewall if you are using it and try again
Please go through this
If your facing delay notification or message problem in GCM then try this solution.
I know this is not proper solution but it's WORKS Install this app it's really work for me HERE