com.parse

## Class ParsePush

- java.lang.Object
- - com.parse.ParsePush

    public class ParsePush
    extends Object

The `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 Summary

Constructors
Constructor and Description
`ParsePush()` Creates a new push notification.

### Method Summary

Methods
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ParsePush

    public ParsePush()

Creates a new push notification. The default channel is the empty string, also known as the global broadcast channel, but this value can be overridden using `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)`.

### Method Detail

#### subscribeInBackground

    public static Task<Void> subscribeInBackground(String channel)

Adds 'channel' to the 'channels' list in the current `ParseInstallation` and saves it in a background thread.

Parameters:
  `channel` - The channel to subscribe to.
Returns:
  A Task that is resolved when the the subscription is complete.

#### subscribeInBackground

    public static void subscribeInBackground(String channel,
                             SaveCallback callback)

Adds 'channel' to the 'channels' list in the current `ParseInstallation` and saves it in a background thread.

Parameters:
  `channel` - The channel to subscribe to.
  `callback` - The SaveCallback that is called after the Installation is saved.

#### unsubscribeInBackground

    public static Task<Void> unsubscribeInBackground(String channel)

Removes 'channel' from the 'channels' list in the current `ParseInstallation` and saves it in a background thread.

Parameters:
  `channel` - The channel to unsubscribe from.
Returns:
  A Task that is resolved when the the unsubscription is complete.

#### unsubscribeInBackground

    public static void unsubscribeInBackground(String channel,
                               SaveCallback callback)

Removes 'channel' from the 'channels' list in the current `ParseInstallation` and saves it in a background thread.

Parameters:
  `channel` - The channel to unsubscribe from.
  `callback` - The SaveCallback that is called after the Installation is saved.

#### sendMessageInBackground

    public static Task<Void> sendMessageInBackground(String message,
                                     ParseQuery<ParseInstallation> query)

A helper method to concisely send a push message to a query. This method is equivalent to ParsePush push = new ParsePush(); push.setMessage(message); push.setQuery(query); push.sendInBackground();

Parameters:
  `message` - The message that will be shown in the notification.
  `query` - A ParseInstallation query which specifies the recipients of a push.
Returns:
  A task that is resolved when the message is sent.

#### sendMessageInBackground

    public static void sendMessageInBackground(String message,
                               ParseQuery<ParseInstallation> query,
                               SendCallback callback)

A helper method to concisely send a push message to a query. This method is equivalent to ParsePush push = new ParsePush(); push.setMessage(message); push.setQuery(query); push.sendInBackground(callback);

Parameters:
  `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.

#### sendDataInBackground

    public static Task<Void> sendDataInBackground(JSONObject data,
                                  ParseQuery<ParseInstallation> query)

A helper method to concisely send a push to a query. This method is equivalent to ParsePush push = new ParsePush(); push.setData(data); push.setQuery(query); push.sendInBackground();

Parameters:
  `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.
Returns:
  A task that is resolved when the data is sent.

#### sendDataInBackground

    public static void sendDataInBackground(JSONObject data,
                            ParseQuery<ParseInstallation> query,
                            SendCallback callback)

A helper method to concisely send a push to a query. This method is equivalent to ParsePush push = new ParsePush(); push.setData(data); push.setQuery(query); push.sendInBackground(callback);

Parameters:
  `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.

#### setChannel

    public void setChannel(String channel)

Sets the channel on which this push notification will be sent. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores. A push can either have channels or a query. Setting this will unset the query.

#### setChannels

    public void setChannels(Collection<String> channels)

Sets the collection of channels on which this push notification will be sent. Each channel name must start with a letter and contain only letters, numbers, dashes, and underscores. A push can either have channels or a query. Setting this will unset the query.

#### setQuery

    public void setQuery(ParseQuery<ParseInstallation> query)

Sets the query for this push for which this push notification will be sent. This query will be executed in the Parse cloud; this push notification will be sent to Installations which this query yields. A push can either have channels or a query. Setting this will unset the channels.

Parameters:
  `query` - A query to which this push should target. This must be a ParseInstallation query.

#### setExpirationTime

    public void setExpirationTime(long time)

Sets a UNIX epoch timestamp at which this notification should expire, in seconds (UTC). This notification will be sent to devices which are either online at the time the notification is sent, or which come online before the expiration time is reached. Because device clocks are not guaranteed to be accurate, most applications should instead use `ParsePush.setExpirationTimeInterval(long)`.

#### setExpirationTimeInterval

    public void setExpirationTimeInterval(long timeInterval)

Sets the time interval after which this notification should expire, in seconds. This notification will be sent to devices which are either online at the time the notification is sent, or which come online within the given number of seconds of the notification being received by Parse's server. An interval which is less than or equal to zero indicates that the message should only be sent to devices which are currently online.

#### clearExpiration

    public void clearExpiration()

Clears both expiration values, indicating that the notification should never expire.

#### setPushToIOS

    @Deprecated
    public 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).
Set whether this push notification will go to iOS devices.

Setting this to `true` will set `ParsePush.setPushToAndroid(boolean)` to `false`.

Note: You must set up iOS push certificates before sending pushes to iOS.

#### setPushToAndroid

    @Deprecated
    public 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).
Set whether this push notification will go to Android devices.

Setting this to `true` will set `ParsePush.setPushToIOS(boolean)` to `false`.

#### setData

    public void setData(JSONObject data)

Sets the entire data of the push message. See the push guide for more details on the data format. This will overwrite any data specified in `ParsePush.setMessage(String)`.

#### setMessage

    public void setMessage(String message)

Sets the message that will be shown in the notification. This will overwrite any data specified in `ParsePush.setData(JSONObject)`.

#### sendInBackground

    public Task<Void> sendInBackground()

Sends this push notification in a background thread. Use this when you do not have code to run on completion of the push.

Returns:
  A Task is resolved when the push has been sent.

#### send

    public void send()
              throws ParseException

Sends this push notification while blocking this thread until the push notification has successfully reached the Parse servers. Typically, you should use `ParsePush.sendInBackground()` instead of this, unless you are managing your own threading.

Throws:
  `ParseException` - Throws an exception if the server is inaccessible.

#### sendInBackground

    public void sendInBackground(SendCallback callback)

Sends this push notification in a background thread. This is preferable to using `send()`, unless your code is already running from a background thread.

Parameters:
  `callback` - callback.done(e) is called when the send completes.