Outgoing GCM Message Sender Identification

I am using Google Cloud Messaging with XMPP to have both outbound and upstream messages.

Only on the client side do I get the token by doing this in a worker thread:

InstanceID instanceID = InstanceID.getInstance(this);

try {
    String token = instanceID.getToken(getString(R.string.gcm_senderID), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

    send_token(token, getString(R.string.gcm_senderID));
} catch (IOException e) {
    e.printStackTrace();
}

      

Then I send this token to the server where it was received. I can send messages to the client with this token.

Then I can send an upstream message on the client side like this:

new AsyncTask<Void, Void, String>() {
    @Override
    protected String doInBackground(Void... params) {
        String msg;

        Bundle data = new Bundle();

        data.putString("message", message);

        try {
            messenger.send(getString(R.string.gcm_senderID) + "@gcm.googleapis.com", messageId.addAndGet(1) + "", data);
        } catch (IOException e) {
            e.printStackTrace();
        }

        msg = "Sent message";

        return msg;
    }
}.execute(null, null, null);

      

The upstream message sent from the client has a field from

that is also a token. If I send a message to the server from the server side, my phone will receive it as well.

What confuses me is that the token in the field is from

not equal to the one generated by the InstanceID service.

The first 18 characters or so are equal, but after that they are very different. So, is there a good way to determine which device sent which message?

I could store the token generated by the instance id every time in Bundle

, but I was wondering if there could be some way to make the from

upstream message field consistent with the generated id.

Edit: Using a deprecated function register

, I was able to get a consistent registration ID.

String token = GoogleCloudMessaging.getInstance().register(getString(R.string.gcm_senderID));

      

But is there a way to do this using InstanceID?

+3


source to share


1 answer


Calling GoogleCloudMessaging.getInstance (context) .register (senderId) instead of getToken (senderId, "GCM") seems to fix the problem, then the XMPP server will get the correct token, every time, in the "from" property of the upstream message.

CyanogenMod is running on my device, so the Google Play app does not automatically update. Since the old register () works, this issue is most likely caused by a bug in google-play-services_lib when talking to an older version of the GMS app.



I replied instead of a comment with the vain hope that Google sees this.

0


source







All Articles