mehrdad khosravi
mehrdad khosravi

Reputation: 2258

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:

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();
}

Upvotes: 3

Views: 1002

Answers (2)

Alaa AlDarf
Alaa AlDarf

Reputation: 69

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

Upvotes: 1

ishmaelMakitla
ishmaelMakitla

Reputation: 3812

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.

Upvotes: 1

Related Questions