1

I am currently using stackmob for push notifications for android and iOS. I am using their java client for sending push notifications.

I am giving the correct API_KEY and API_SECRET. The deviceToken is also correct still it sometimes gives me a 401 error and sometimes a 200 status code but I am not able to receive any push notifications. This is my sample code.

public class TestSample {

public static String API_KEY = "Some key";

public static String API_SECRET = "Some key";

public static String USER_OBJECT_NAME = "user";
public static int API_VERSION = 0;

public static void main(String[] args) {

       new TestSample();
}

public TestSample()
{       
    String deviceToken="Token";
    init();
    StackMob stackmob=getStackMobInstance();

    stackmob.registerForPushWithUser("rathi", deviceToken, new StackMobRawCallback() {

        @Override
        public void done(HttpVerb arg0, String arg1,
                List<Entry<String, String>> arg2, String arg3, Integer arg4,
                List<Entry<String, String>> arg5, byte[] arg6) {

             System.out.println("HEree1");
        }
    });


    StackMobPushToken x=new StackMobPushToken(registrationID, TokenType.iOS);

    final Map<String, String> payload = new HashMap<String, String>();
    ArrayList<StackMobPushToken>tokens=new ArrayList<StackMobPushToken>(); 
    tokens.add(x);

      payload.put("badge", "1");
      payload.put("sound", "customsound.wav");
      payload.put("alert", "Hello from Stackmob!");
      payload.put("other", "stuff");

    stackmob.pushToTokens(payload, tokens, new StackMobRawCallback() {

        @Override
        public void done(HttpVerb arg0, String arg1,
                List<Entry<String, String>> arg2, String arg3, Integer arg4,
                List<Entry<String, String>> arg5, byte[] arg6) {
             System.out.println("HEree");

        }
    });
}


public  void init() {
    StackMob.setStackMob(new StackMob(API_KEY, API_SECRET, USER_OBJECT_NAME, API_VERSION));
    //StackMob.getStackMob().setSession(new StackMobAndroidSession(c, StackMob.getStackMob().getSession()));
    StackMob.getStackMob().setSession(new StackMobSession(StackMob.getStackMob().getSession()));

    StackMob.setUserAgentName("iOS");
    StackMob.setLogger(new StackMobLogger());
    StackMob.getLogger().setLogging(true);
    StackMobRequest.setCookieStore(new StackMobCookieStore());

}

public static StackMob getStackMobInstance() {
    return StackMob.getStackMob();
}

}

Rathi
  • 71
  • 1
  • 7

1 Answers1

1

A few comments:

  • What is this code supposed to do exactly? First you register a user "rathi" with a fake device token "Token". Then you send a push to a token registrationID that doesn't seem to be defined anywhere. Are you expecting a push notification to show up in your java client? The whole push notification concept is tied to phones

  • If registrationID refers to a token previously registered on a phone, then the call you make with it ought to work. Normally I'd expect a client like yours to be calling pushToUsers() and broadcastPushNotification() rather than dealing directly with tokens. The StackMob API is meant to abstract away those implementation details

  • If you're still having problems, can you post the console output you get? I see you have logging turned on already. Updating to the latest sdk is also always good.

Douglas Rapp
  • 360
  • 2
  • 5