java.lang.Object | |
↳ | com.google.android.gcm.server.Sender |
Helper class to send messages to the GCM service using an API Key.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | BACKOFF_INITIAL_DELAY | Initial delay before first retry, without jitter. | |||||||||
int | MAX_BACKOFF_DELAY | Maximum delay before a retry. | |||||||||
String | UTF8 |
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
logger | |||||||||||
random |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sends a message to many devices, retrying in case of unavailability.
| |||||||||||
Sends a message to one device, retrying in case of unavailability.
| |||||||||||
Sends a message without retrying in case of service unavailability.
| |||||||||||
Sends a message without retrying in case of service unavailability.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a new parameter to the HTTP POST body.
| |||||||||||
Gets an
HttpURLConnection given an URL. | |||||||||||
Convenience method to convert an InputStream to a String.
| |||||||||||
Creates a
StringBuilder to be used as the body of an HTTP POST. | |||||||||||
Creates a map with just one key-value pair.
| |||||||||||
Makes an HTTP POST request to a given endpoint.
| |||||||||||
Make an HTTP post to a given URL.
|
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Initial delay before first retry, without jitter.
Maximum delay before a retry.
Default constructor.
key | API key obtained through the Google API Console. |
---|
Sends a message to many devices, retrying in case of unavailability.
Note: this method uses exponential back-off to retry in case of service unavailability and hence could block the calling thread for many seconds.
message | message to be sent. |
---|---|
regIds | registration id of the devices that will receive the message. |
retries | number of retries in case of service unavailability errors. |
IllegalArgumentException | if registrationIds is null or empty. |
---|---|
InvalidRequestException | if GCM didn't returned a 200 or 503 status. |
IOException | if message could not be sent. |
Sends a message to one device, retrying in case of unavailability.
Note: this method uses exponential back-off to retry in case of service unavailability and hence could block the calling thread for many seconds.
message | message to be sent, including the device's registration id. |
---|---|
registrationId | device where the message will be sent. |
retries | number of retries in case of service unavailability errors. |
IllegalArgumentException | if registrationId is null. |
---|---|
InvalidRequestException | if GCM didn't returned a 200 or 5xx status. |
IOException | if message could not be sent. |
Sends a message without retrying in case of service unavailability. See
send(Message, String, int)
for more info.
InvalidRequestException | if GCM didn't returned a 200 or 5xx status. |
---|---|
IllegalArgumentException | if registrationId is null. |
IOException |
Sends a message without retrying in case of service unavailability. See
send(Message, List, int)
for more info.
IllegalArgumentException | if registrationIds is null or empty. |
---|---|
InvalidRequestException | if GCM didn't returned a 200 status. |
IOException | if there was a JSON parsing error |
Adds a new parameter to the HTTP POST body.
body | HTTP POST body. |
---|---|
name | parameter's name. |
value | parameter's value. |
Gets an HttpURLConnection
given an URL.
IOException |
---|
Convenience method to convert an InputStream to a String.
If the stream ends in a newline character, it will be stripped.
If the stream is null, returns an empty string.
IOException |
---|
Creates a StringBuilder
to be used as the body of an HTTP POST.
name | initial parameter for the POST. |
---|---|
value | initial value for that parameter. |
Creates a map with just one key-value pair.
Makes an HTTP POST request to a given endpoint.
Note: the returned connected should not be disconnected, otherwise it would kill persistent connections made using Keep-Alive.
url | endpoint to post the request. |
---|---|
contentType | type of request. |
body | body of the request. |
IOException | propagated from underlying methods. |
---|
Make an HTTP post to a given URL.
IOException |
---|