public class ParsePush extends Object
ParsePush
is a local representation of data that can be sent as a push notification.
The typical workflow for sending a push notification from the client is to construct a new
ParsePush
, use the setter functions to fill it with data, and then use
ParsePush.sendInBackground()
to send it.Constructor and Description |
---|
ParsePush()
Creates a new push notification.
|
Modifier and Type | Method and Description |
---|---|
void |
clearExpiration()
Clears both expiration values, indicating that the notification should never expire.
|
void |
send()
Sends this push notification while blocking this thread until the push notification has
successfully reached the Parse servers.
|
static Task<Void> |
sendDataInBackground(JSONObject data,
ParseQuery<ParseInstallation> query)
A helper method to concisely send a push to a query.
|
static void |
sendDataInBackground(JSONObject data,
ParseQuery<ParseInstallation> query,
SendCallback callback)
A helper method to concisely send a push to a query.
|
Task<Void> |
sendInBackground()
Sends this push notification in a background thread.
|
void |
sendInBackground(SendCallback callback)
Sends this push notification in a background thread.
|
static Task<Void> |
sendMessageInBackground(String message,
ParseQuery<ParseInstallation> query)
A helper method to concisely send a push message to a query.
|
static void |
sendMessageInBackground(String message,
ParseQuery<ParseInstallation> query,
SendCallback callback)
A helper method to concisely send a push message to a query.
|
void |
setChannel(String channel)
Sets the channel on which this push notification will be sent.
|
void |
setChannels(Collection<String> channels)
Sets the collection of channels on which this push notification will be sent.
|
void |
setData(JSONObject data)
Sets the entire data of the push message.
|
void |
setExpirationTime(long time)
Sets a UNIX epoch timestamp at which this notification should expire, in seconds (UTC).
|
void |
setExpirationTimeInterval(long timeInterval)
Sets the time interval after which this notification should expire, in seconds.
|
void |
setMessage(String message)
Sets the message that will be shown in the notification.
|
void |
setPushToAndroid(boolean pushToAndroid)
Deprecated.
Please use
ParsePush.setQuery(ParseQuery) with a ParseQuery targeting
ParseInstallation s with a constraint on the deviceType field. If you use
#setPushToAndroid(boolean) or ParsePush.setPushToIOS(boolean) , then you will only be
able to send to one of these two device types (e.g. and not Windows). |
void |
setPushToIOS(boolean pushToIOS)
Deprecated.
Please use
ParsePush.setQuery(ParseQuery) with a ParseQuery targeting
ParseInstallation s with a constraint on the deviceType field. If you use
#setPushToIOS(boolean) or ParsePush.setPushToAndroid(boolean) , then you will only be
able to send to one of these two device types (e.g. and not Windows). |
void |
setQuery(ParseQuery<ParseInstallation> query)
Sets the query for this push for which this push notification will be sent.
|
static Task<Void> |
subscribeInBackground(String channel)
Adds 'channel' to the 'channels' list in the current
ParseInstallation and saves it in
a background thread. |
static void |
subscribeInBackground(String channel,
SaveCallback callback)
Adds 'channel' to the 'channels' list in the current
ParseInstallation and saves it in
a background thread. |
static Task<Void> |
unsubscribeInBackground(String channel)
Removes 'channel' from the 'channels' list in the current
ParseInstallation and saves
it in a background thread. |
static void |
unsubscribeInBackground(String channel,
SaveCallback callback)
Removes 'channel' from the 'channels' list in the current
ParseInstallation and saves
it in a background thread. |
public ParsePush()
ParsePush.setChannel(String)
,
ParsePush.setChannels(Collection)
or ParsePush.setQuery(ParseQuery)
. Before sending the push
notification you must call either ParsePush.setMessage(String)
or ParsePush.setData(JSONObject)
.public static Task<Void> subscribeInBackground(String channel)
ParseInstallation
and saves it in
a background thread.channel
- The channel to subscribe to.public static void subscribeInBackground(String channel, SaveCallback callback)
ParseInstallation
and saves it in
a background thread.channel
- The channel to subscribe to.callback
- The SaveCallback that is called after the Installation is saved.public static Task<Void> unsubscribeInBackground(String channel)
ParseInstallation
and saves
it in a background thread.channel
- The channel to unsubscribe from.public static void unsubscribeInBackground(String channel, SaveCallback callback)
ParseInstallation
and saves
it in a background thread.channel
- The channel to unsubscribe from.callback
- The SaveCallback that is called after the Installation is saved.public static Task<Void> sendMessageInBackground(String message, ParseQuery<ParseInstallation> query)
message
- The message that will be shown in the notification.query
- A ParseInstallation query which specifies the recipients of a push.public static void sendMessageInBackground(String message, ParseQuery<ParseInstallation> query, SendCallback callback)
message
- The message that will be shown in the notification.query
- A ParseInstallation query which specifies the recipients of a push.callback
- callback.done(e) is called when the send completes.public static Task<Void> sendDataInBackground(JSONObject data, ParseQuery<ParseInstallation> query)
data
- The entire data of the push message. See the push guide for more details on the data
format.query
- A ParseInstallation query which specifies the recipients of a push.public static void sendDataInBackground(JSONObject data, ParseQuery<ParseInstallation> query, SendCallback callback)
data
- The entire data of the push message. See the push guide for more details on the data
format.query
- A ParseInstallation query which specifies the recipients of a push.callback
- callback.done(e) is called when the send completes.public void setChannel(String channel)
public void setChannels(Collection<String> channels)
public void setQuery(ParseQuery<ParseInstallation> query)
query
- A query to which this push should target. This must be a ParseInstallation query.public void setExpirationTime(long time)
ParsePush.setExpirationTimeInterval(long)
.public void setExpirationTimeInterval(long timeInterval)
public void clearExpiration()
@Deprecated public void setPushToIOS(boolean pushToIOS)
ParsePush.setQuery(ParseQuery)
with a ParseQuery
targeting
ParseInstallation
s with a constraint on the deviceType
field. If you use
#setPushToIOS(boolean)
or ParsePush.setPushToAndroid(boolean)
, then you will only be
able to send to one of these two device types (e.g. and not Windows).true
will set ParsePush.setPushToAndroid(boolean)
to false
.
Note: You must set up iOS push certificates before sending pushes to iOS.@Deprecated public void setPushToAndroid(boolean pushToAndroid)
ParsePush.setQuery(ParseQuery)
with a ParseQuery
targeting
ParseInstallation
s with a constraint on the deviceType
field. If you use
#setPushToAndroid(boolean)
or ParsePush.setPushToIOS(boolean)
, then you will only be
able to send to one of these two device types (e.g. and not Windows).true
will set ParsePush.setPushToIOS(boolean)
to false
.public void setData(JSONObject data)
ParsePush.setMessage(String)
.public void setMessage(String message)
ParsePush.setData(JSONObject)
.public Task<Void> sendInBackground()
public void send() throws ParseException
ParsePush.sendInBackground()
instead of this, unless you are managing your own threading.ParseException
- Throws an exception if the server is inaccessible.public void sendInBackground(SendCallback callback)
send()
, unless your code is already running from a background thread.callback
- callback.done(e) is called when the send completes.