Package com.parse

Class ParsePush


  • public class ParsePush
    extends java.lang.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 sendInBackground() to send it.

    • Constructor Detail

      • ParsePush

        public ParsePush​(ParsePush push)
        Creates a copy of push.
        Parameters:
        push - The push to copy.
    • Method Detail

      • subscribeInBackground

        public static <any> subscribeInBackground​(java.lang.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​(java.lang.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 <any> unsubscribeInBackground​(java.lang.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​(java.lang.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 <any> sendMessageInBackground​(java.lang.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​(java.lang.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 <any> 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​(java.lang.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​(java.util.Collection<java.lang.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 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.
      • setPushTime

        public void setPushTime​(long time)
        Sets a UNIX epoch timestamp at which this notification should be delivered, in seconds (UTC). Scheduled time can not be in the past and must be at most two weeks in the future.
      • 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 setMessage(String).
      • setMessage

        public void setMessage​(java.lang.String message)
        Sets the message that will be shown in the notification. This will overwrite any data specified in #setData(JSONObject).
      • sendInBackground

        public <any> 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 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.