Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM - pubSub.subscribe not working

I'm using GCM in my android client and I already can push notification from my App server to Android client.

But I cannot subscribe for a topic I use pubSub.subscribe method and pass registration token and custom topic name in the format of "/topics/mytopic". Here are the thing I'm done so far:

  • I wrap the method inside try and catch and it doesn't throw any exceptions.
  • I have debugged HTTP via Fiddler but when it does not send any request.
  • I try get information of token id via https://iid.googleapis.com/iid/info/IID_TOKEN but it doesn't return any subscribed topics for the client.

here the publish code in android intent service:

GcmPubSub pubSub = GcmPubSub.getInstance(this);
try
{
    pubSub.subscribe(token, "/topics/mytopic",null);
} catch (IOException e)
{
    e.printStackTrace();
}
like image 340
mehrdad khosravi Avatar asked Mar 03 '26 06:03

mehrdad khosravi


2 Answers

I am not sure if you have seen this example IntentService which shows how to subscribe to topics. Please check it out and see how far you get - it sounds like something you are trying to do. Check specifically the way the token string gets created which is then used in the subscription:

 InstanceID instanceID = InstanceID.getInstance(this);
 String token = instanceID.getToken(SENDER_ID,GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

According to the solution to a token issue here, obtaining the token has to be via using InstanceID - otherwise you get issues with topic subscriptions.

like image 103
ishmaelMakitla Avatar answered Mar 04 '26 18:03

ishmaelMakitla


You are using the Main Thread,you should use another thread Try adding your subscribe code to AsyncTask or IntentService

like image 44
Alaa AlDarf Avatar answered Mar 04 '26 18:03

Alaa AlDarf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!