com.stackmob.sdk.push
Class StackMobPush

java.lang.Object
  extended by com.stackmob.sdk.push.StackMobPush

public class StackMobPush
extends Object


Field Summary
static String DEFAULT_PUSH_HOST
           
 
Constructor Summary
StackMobPush(int apiVersionNumber, String apiKey, String apiSecret)
          a minimal constructor, using defaults for everything else
StackMobPush(int apiVersionNumber, String apiKey, String apiSecret, String host, StackMobRedirectedCallback redirectedCallback)
          the most complete constructor
StackMobPush(StackMob stackmob)
          create a StackMobPush based on a StackMob object and defaults elsewhere.
StackMobPush(StackMob stackmob, String host)
          create a StackMobPush based on a StackMob object and the given host
 
Method Summary
 void broadcastPushNotification(Map<String,String> payload, StackMobRawCallback callback)
          broadcast a push notification to all users of this app.
static StackMobPush getPush()
          get the singleton StackMobPush object
 void getTokensForUsers(List<String> usernames, StackMobRawCallback callback)
          get all the tokens for the each of the given users
 void pushToTokens(Map<String,String> payload, List<StackMobPushToken> tokens, StackMobRawCallback callback)
          send a push notification to a group of tokens
 void pushToUsers(Map<String,String> payload, List<String> userIds, StackMobRawCallback callback)
          send a push notification to a group of users.
 void registerForPushWithUser(StackMobPushToken token, String username, boolean overwrite, StackMobRawCallback callback)
          register a user for Android Push notifications.
 void registerForPushWithUser(StackMobPushToken token, String username, StackMobRawCallback callback)
          register a user for Android Push notifications.
 void removePushToken(StackMobPushToken token, StackMobRawCallback callback)
          remove a push token for this app
static void setPush(StackMobPush push)
          set the singletone StackMobPush
static void setPushType(StackMobPushToken.TokenType type)
          Sets the type of push this StackMob instance will do.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PUSH_HOST

public static String DEFAULT_PUSH_HOST
Constructor Detail

StackMobPush

public StackMobPush(int apiVersionNumber,
                    String apiKey,
                    String apiSecret)
a minimal constructor, using defaults for everything else

Parameters:
apiVersionNumber - the version of your app's API that you want to use with this StackMob session. pass 0 for sandbox
apiKey - the api key for your app
apiSecret - the api secret for your app. Can be null if you're using OAuth2

StackMobPush

public StackMobPush(int apiVersionNumber,
                    String apiKey,
                    String apiSecret,
                    String host,
                    StackMobRedirectedCallback redirectedCallback)
the most complete constructor

Parameters:
apiVersionNumber - the version of your app's API that you want to use with this StackMob session. pass 0 for sandbox
apiKey - the api key for your app
apiSecret - the api secret for your app. Can be null if you're using OAuth2
host - the base url for requests
redirectedCallback - callback to be called if the StackMob platform issues a redirect. you should use this callback to cache the new URLs. here is a sample callback: new StackMobRedirectedCallback() { public void redirected(HttpRequest origRequest, HttpResponse response, HttpRequest newRequest) { try { URI uri = new URI(newRequest.getRequestLine().getUri()); cache(uri.getHost); } catch (URISyntaxException e) { handleException(e); } } } } note that this callback may be called in a background thread

StackMobPush

public StackMobPush(StackMob stackmob)
create a StackMobPush based on a StackMob object and defaults elsewhere.

Parameters:
stackmob - the StackMob object to get values from

StackMobPush

public StackMobPush(StackMob stackmob,
                    String host)
create a StackMobPush based on a StackMob object and the given host

Parameters:
stackmob - the StackMob object to get values from
host - the base url for requests
Method Detail

setPushType

public static void setPushType(StackMobPushToken.TokenType type)
Sets the type of push this StackMob instance will do. The default is GCM. Use this to switch back to C2DM if you need to

Parameters:
type - C2DM or GCM

getPush

public static StackMobPush getPush()
get the singleton StackMobPush object

Returns:
the singleton

setPush

public static void setPush(StackMobPush push)
set the singletone StackMobPush

Parameters:
push - the new singleton

pushToTokens

public void pushToTokens(Map<String,String> payload,
                         List<StackMobPushToken> tokens,
                         StackMobRawCallback callback)
send a push notification to a group of tokens

Parameters:
payload - the payload of the push notification to send
tokens - the tokens to which to send
callback - callback to be called when the server returns. may execute in a separate thread

pushToUsers

public void pushToUsers(Map<String,String> payload,
                        List<String> userIds,
                        StackMobRawCallback callback)
send a push notification to a group of users.

Parameters:
payload - the payload to send
userIds - the IDs of the users to which to send
callback - callback to be called when the server returns. may execute in a separate thread

registerForPushWithUser

public void registerForPushWithUser(StackMobPushToken token,
                                    String username,
                                    StackMobRawCallback callback)
register a user for Android Push notifications. This uses GCM unless specified otherwise.

Parameters:
token - a token containing a registration id and platform
username - the StackMob username to associate with this token
callback - callback to be called when the server returns. may execute in a separate thread

registerForPushWithUser

public void registerForPushWithUser(StackMobPushToken token,
                                    String username,
                                    boolean overwrite,
                                    StackMobRawCallback callback)
register a user for Android Push notifications.

Parameters:
token - a token containing a registration id and platform
username - the StackMob username to associate with this token
overwrite - whether to overwrite existing entries
callback - callback to be called when the server returns. may execute in a separate thread

getTokensForUsers

public void getTokensForUsers(List<String> usernames,
                              StackMobRawCallback callback)
get all the tokens for the each of the given users

Parameters:
usernames - the users whose tokens to get
callback - callback to be called when the server returns. may execute in a separate thread

broadcastPushNotification

public void broadcastPushNotification(Map<String,String> payload,
                                      StackMobRawCallback callback)
broadcast a push notification to all users of this app. use this method sparingly, especially if you have a large app

Parameters:
payload - the payload to broadcast
callback - callback to be called when the server returns. may execute in a separate thread

removePushToken

public void removePushToken(StackMobPushToken token,
                            StackMobRawCallback callback)
remove a push token for this app

Parameters:
token - the token
callback - callback to be called when the server returns. may execute in a separate thread


Copyright © 2012 StackMob. All Rights Reserved.