Class WonderPush
You would normally only interact with this class, which has all static members.
Make sure you properly installed the WonderPush SDK, as described in the guide.
You must call initialize(Context)
before using any other function.
Troubleshooting tip: As the SDK should not interfere with your application other than when a notification is to be shown, make sure to monitor your logs for the WonderPush tag during development, if things did not went as smoothly as they should have.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Local intent broadcast when an event is tracked by the WonderPush SDK.static final String
Intent extra key holding custom data serialized as JSON of event being tracked.static final String
Intent extra key holding the type of event being tracked.static final String
Intent extra key holding occurences data serialized as JSON of event being tracked.static final String
Intent action for notification button action `method`.static final String
Intent authority for notification button action `method`.static final String
Intent query parameter key for the notification button action `method` argument.static final String
Intent query parameter key for the notification button action `method` method name.static final String
Intent scheme for notification button action `method`.static final String
Local intent broadcasted when a push notification created by the WonderPush SDK has been opened.static final String
The extra key indicating which action button the user clicked on the notification in aINTENT_NOTIFICATION_OPENED
intent.static final String
The extra key for whether the user clicked the notification or it was automatically opened by the SDK in aINTENT_NOTIFICATION_OPENED
intent.static final String
The extra key for the parsed notification in aINTENT_NOTIFICATION_OPENED
intent.static final String
The extra key for the original received push notification intent in aINTENT_NOTIFICATION_OPENED
intent.static final String
Local intent broadcasted when a push notification created by the WonderPush SDK is to be opened, but no activity is to be started.static final String
The extra key denoting whether to automatically display a rich notification message in aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
The extra key indicating which action button the user clicked on the notification in aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
The extra key for whether the user clicked the notification or it was automatically opened by the SDK in aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
The extra key for the parsed notification in aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
The extra key denoting the received push notification type, for aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
The value associated to data push notifications (aka silent notifications), corresponding to the extra keyINTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE
.static final String
The extra key for the original received push notification intent in aINTENT_NOTIFICATION_WILL_OPEN
intent.static final String
Local intent broadcasted when the push token has changed.static final String
The extra key for the previously known push token, can be null.static final String
The extra key for the new push token, can be null. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addProperty
(String field, Object value) Adds the value to a given property attached to the current installation object stored by WonderPush.static void
Add one or more tags to the current installation object stored by WonderPush.static void
clearAll()
Deprecated.static void
Remove any local storage and ask the WonderPush servers to delete any data associated with the all local installations and related users.static void
Ask the WonderPush servers to delete any event associated with the all local installations.static void
Ask the WonderPush servers to delete any custom data associated with the all local installations and related users.static void
Disables the collection of the user's geolocation.static void
Exports all data stored locally and on WonderPush servers and then starts a sharing activity for the user to save it.static void
Enables the collection of the user's geolocation.static String
Gets the access token, used to grant access to the current installation to the WonderPush REST API.static String
Gets the user's country, either as previously stored, or as guessed from the system.static String
Gets the user's currency, either as previously stored, or as guessed from the system.static WonderPushDelegate
Returns the configured delegate, ornull
if none was set.static String
Gets the device id, used to identify a single device, and to correctly identify multiple users on a single device.static org.json.JSONObject
Deprecated.static String
Gets the device id, used to identify a single device across applications, and to correctly identify multiple users on a single device.static String
Gets the user's locale, either as previously stored, or as guessed from the system.static boolean
Whether debug logging is enabled.static boolean
Deprecated.static org.json.JSONObject
Returns the latest known properties attached to the current installation object stored by WonderPush.static Object
getPropertyValue
(String field) Returns the value of a given property attached to the current installation object stored by WonderPush.getPropertyValues
(String field) Returns an immutable list of the values of a given property attached to the current installation object stored by WonderPush.static String
Gets the push token, used to send notification to this installation.getTags()
Returns all the tags of the current installation object stored by WonderPush.static String
Gets the user's time zone, either as previously stored, or as guessed from the system.static boolean
Returns whether user consent has already provided consent.static String
Gets the user id, used to identify a single identity across multiple devices, and to correctly identify multiple users on a single device.static boolean
Test whether the current installation has the given tag attached to it.static void
initialize
(android.content.Context context) Initialize WonderPush.static void
initialize
(android.content.Context context, String clientId, String clientSecret) Initialize WonderPush from yourWonderPushInitializer
implementation.static boolean
Returns whether push notification are enabled.static void
putInstallationCustomProperties
(org.json.JSONObject customProperties) Deprecated.static void
putProperties
(org.json.JSONObject properties) Update the properties attached to the current installation object stored by WonderPush.static void
Remove all tags from the current installation object stored by WonderPush.static void
removeProperty
(String field, Object value) Removes the value from a given property attached to the current installation object stored by WonderPush.static void
Remove one or more tags from the current installation object stored by WonderPush.static void
setCountry
(String country) Overrides the user's country.static void
setCurrency
(String currency) Overrides the user's currency.static void
setDelegate
(WonderPushDelegate delegate) Configures a delegate for tighter integration with the SDK.static void
setGeolocation
(android.location.Location location) Overrides the user's geolocation.static void
setIntegrator
(String integrator) Sets the framework, library or wrapper used for integration.static void
Overrides the user's locale.static void
setLogging
(boolean enable) Whether to enable debug logging.static void
setNotificationEnabled
(boolean status) Deprecated.static void
setProperty
(String field, Object value) Sets the value to a given property attached to the current installation object stored by WonderPush.static void
setRequiresUserConsent
(boolean value) Sets whether user consent is required before the SDK is allowed to work.static void
setTimeZone
(String timeZone) Overrides the user's timeZone.static void
setUserConsent
(boolean value) Provides or withdraws user consent.static void
Sets the user id, used to identify a single identity across multiple devices, and to correctly identify multiple users on a single device.static void
Enables push notifications for the current device.static void
subscribeToNotifications
(boolean fallbackToSettings) Enables push notifications for the current devicestatic void
trackEvent
(String type) Send an event to be tracked to WonderPush.static void
trackEvent
(String type, org.json.JSONObject attributes) Send an event to be tracked to WonderPush.static void
unsetProperty
(String field) Removes the value of a given property attached to the current installation object stored by WonderPush.static void
Disables push notifications for the current device.
-
Field Details
-
INTENT_PUSH_TOKEN_CHANGED
Local intent broadcasted when the push token has changed.- See Also:
-
INTENT_PUSH_TOKEN_CHANGED_EXTRA_OLD_KNOWN_PUSH_TOKEN
The extra key for the previously known push token, can be null.- See Also:
-
INTENT_PUSH_TOKEN_CHANGED_EXTRA_PUSH_TOKEN
The extra key for the new push token, can be null.- See Also:
-
INTENT_NOTIFICATION_OPENED
Local intent broadcasted when a push notification created by the WonderPush SDK has been opened.- See Also:
-
INTENT_NOTIFICATION_OPENED_EXTRA_RECEIVED_PUSH_NOTIFICATION
The extra key for the original received push notification intent in aINTENT_NOTIFICATION_OPENED
intent.- See Also:
-
INTENT_NOTIFICATION_OPENED_EXTRA_NOTIFICATION_MODEL
The extra key for the parsed notification in aINTENT_NOTIFICATION_OPENED
intent.- See Also:
-
INTENT_NOTIFICATION_OPENED_EXTRA_FROM_USER_INTERACTION
The extra key for whether the user clicked the notification or it was automatically opened by the SDK in aINTENT_NOTIFICATION_OPENED
intent.- See Also:
-
INTENT_NOTIFICATION_OPENED_EXTRA_BUTTON_INDEX
The extra key indicating which action button the user clicked on the notification in aINTENT_NOTIFICATION_OPENED
intent.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN
Local intent broadcasted when a push notification created by the WonderPush SDK is to be opened, but no activity is to be started. This let's you handledata
notifications or any deep linking yourself.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_RECEIVED_PUSH_NOTIFICATION
The extra key for the original received push notification intent in aINTENT_NOTIFICATION_WILL_OPEN
intent.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_MODEL
The extra key for the parsed notification in aINTENT_NOTIFICATION_WILL_OPEN
intent.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_FROM_USER_INTERACTION
The extra key for whether the user clicked the notification or it was automatically opened by the SDK in aINTENT_NOTIFICATION_WILL_OPEN
intent.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_AUTOMATIC_OPEN
The extra key denoting whether to automatically display a rich notification message in aINTENT_NOTIFICATION_WILL_OPEN
intent. You can set this property tofalse
in your BroadcastReceiver.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE
The extra key denoting the received push notification type, for aINTENT_NOTIFICATION_WILL_OPEN
intent. You can test this property againstINTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE_DATA
in your BroadcastReceiver.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE_DATA
The value associated to data push notifications (aka silent notifications), corresponding to the extra keyINTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE
.- See Also:
-
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_BUTTON_INDEX
The extra key indicating which action button the user clicked on the notification in aINTENT_NOTIFICATION_WILL_OPEN
intent.- See Also:
-
INTENT_EVENT_TRACKED
Local intent broadcast when an event is tracked by the WonderPush SDK.- See Also:
-
INTENT_EVENT_TRACKED_EVENT_TYPE
Intent extra key holding the type of event being tracked.- See Also:
-
INTENT_EVENT_TRACKED_CUSTOM_DATA
Intent extra key holding custom data serialized as JSON of event being tracked.- See Also:
-
INTENT_EVENT_TRACKED_OCCURRENCES
Intent extra key holding occurences data serialized as JSON of event being tracked.- See Also:
-
INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_ACTION
Intent action for notification button action `method`.- See Also:
-
INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_SCHEME
Intent scheme for notification button action `method`.- See Also:
-
INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_AUTHORITY
Intent authority for notification button action `method`.- See Also:
-
INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_EXTRA_METHOD
Intent query parameter key for the notification button action `method` method name.- See Also:
-
INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_EXTRA_ARG
Intent query parameter key for the notification button action `method` argument.- See Also:
-
-
Method Details
-
setLogging
public static void setLogging(boolean enable) Whether to enable debug logging. You should not do this in production builds.- Parameters:
enable
-true
to enable debug logs.
-
getLogging
public static boolean getLogging()Whether debug logging is enabled. -
disableGeolocation
public static void disableGeolocation()Disables the collection of the user's geolocation. -
enableGeolocation
public static void enableGeolocation()Enables the collection of the user's geolocation. You still need the appropriate geolocation permissions in your AndroidManifest.xml to be able to read the user's location. -
setGeolocation
public static void setGeolocation(android.location.Location location) Overrides the user's geolocation.Using this method you can have the user's location be set to wherever you want. This may be useful to use a pre-recorded location.
Note that the value is not persisted.
- Parameters:
location
- The location to use as the user's current geolocation. Usingnull
has the same effect as callingdisableGeolocation()
.
-
setLocale
Overrides the user's locale.You should use an
xx-XX
form of RFC 1766, composed of a lowercase ISO 639-1 language code, an underscore or a dash, and an uppercase ISO 3166-1 alpha-2 country code.Defaults to getting the language and country codes from the system default locale.
- Parameters:
locale
- The locale to use as the user's locale. Usenull
to disable the override.
-
getLocale
Gets the user's locale, either as previously stored, or as guessed from the system.- Returns:
- The user's locale.
- See Also:
-
setCountry
Overrides the user's country.You should use an ISO 3166-1 alpha-2 country code.
Defaults to getting the country code from the system default locale.
- Parameters:
country
- The country to use as the user's country. Usenull
to disable the override.
-
getCountry
Gets the user's country, either as previously stored, or as guessed from the system.- Returns:
- The user's country.
- See Also:
-
setCurrency
Overrides the user's currency.You should use an ISO 4217 currency code.
Defaults to getting the currency code from the system default locale.
- Parameters:
currency
- The currency to use as the user's currency. Usenull
to disable the override.
-
getCurrency
Gets the user's currency, either as previously stored, or as guessed from the system.- Returns:
- The user's currency.
- See Also:
-
setTimeZone
Overrides the user's timeZone.You should use an IANA time zone database codes,
Continent/Country
style preferably, abbreviations likeCET
,PST
,UTC
, which have the drawback of changing on daylight saving transitions.Defaults to getting the time zone code from the system default locale.
- Parameters:
timeZone
- The time zone to use as the user's time zone. Usenull
to disable the override.
-
getTimeZone
Gets the user's time zone, either as previously stored, or as guessed from the system.- Returns:
- The user's time zone.
- See Also:
-
getProperties
public static org.json.JSONObject getProperties()Returns the latest known properties attached to the current installation object stored by WonderPush.Returns an empty
JSONObject
if called without required user consent. -
putProperties
public static void putProperties(org.json.JSONObject properties) Update the properties attached to the current installation object stored by WonderPush.In order to remove a value, don't forget to use the JSONObject.NULL object as value.
Does nothing if called without required user consent.
- Parameters:
properties
- The partial object containing only the properties to update.
-
setProperty
Sets the value to a given property attached to the current installation object stored by WonderPush. The previous value is replaced entirely. The value can be a String, Boolean, Number (coerced to Long or Double), JSONObject, JSONArray, or JSONObject.NULL (which has the same effect asunsetProperty(String)
).Does nothing if called without required user consent.
- Parameters:
field
- The name of the property to setvalue
- The value to be set, can be an array or Collection
-
unsetProperty
Removes the value of a given property attached to the current installation object stored by WonderPush. The previous value is replaced withJSONObject.NULL
.Does nothing if called without required user consent.
- Parameters:
field
- The name of the property to set
-
addProperty
Adds the value to a given property attached to the current installation object stored by WonderPush. The stored value is made an array if not already one. If the given value is an array, all its values are added. If a value is already present in the stored value, it won't be added.Does nothing if called without required user consent.
- Parameters:
field
- The name of the property to add values tovalue
- The value(s) to be added, can be an array
-
removeProperty
Removes the value from a given property attached to the current installation object stored by WonderPush. The stored value is made an array if not already one. If the given value is an array, all its values are removed. If a value is present multiple times in the stored value, they will all be removed.- Parameters:
field
- The name of the property to remove values fromvalue
- The value(s) to be removed, can be an array
-
getPropertyValue
Returns the value of a given property attached to the current installation object stored by WonderPush. If the property stores an array, only the first value is returned. This way you don't have to deal with potential arrays if that property is not supposed to hold one. ReturnsJSONObject.NULL
instead ofnull
if the property is absent or has an empty array value.- Parameters:
field
- The name of the property to read values from- Returns:
JSONObject.NULL
or a single value stored in the property, never aJSONArray
ornull
-
getPropertyValues
Returns an immutable list of the values of a given property attached to the current installation object stored by WonderPush. If the property does not store an array, a list is returned nevertheless. This way you don't have to deal with potential scalar values if that property is supposed to hold an array. Returns an empty list instead ofJSONObject.NULL
ornull
if the property is absent. Returns a list wrapping any scalar value held by the property.Note, the returned value is an immutable list.
- Parameters:
field
- The name of the property to read values from- Returns:
- A possibly empty
JSONArray
of the values stored in the property, but neverJSONObject.NULL
nornull
-
getInstallationCustomProperties
Deprecated.Returns the latest known custom properties attached to the current installation object stored by WonderPush.Use
getProperties()
instead.Returns an empty
JSONObject
if called without required user consent.- See Also:
-
putInstallationCustomProperties
@Deprecated public static void putInstallationCustomProperties(org.json.JSONObject customProperties) Deprecated.Update the custom properties attached to the current installation object stored by WonderPush.Use
putProperties(JSONObject)
instead.In order to remove a value, don't forget to use the JSONObject.NULL object as value.
Does nothing if called without required user consent.
- Parameters:
customProperties
- The partial object containing only the properties to update.- See Also:
-
trackEvent
Send an event to be tracked to WonderPush.Does nothing if called without required user consent.
- Parameters:
type
- The event type, or name. Event types starting with an@
character are reserved.
-
trackEvent
Send an event to be tracked to WonderPush.Does nothing if called without required user consent.
- Parameters:
type
- The event type, or name. Event types starting with an@
character are reserved.attributes
- A JSON object containing attributes to be attached to the event. Prefer using a few attributes over a plethora of event type variants.
-
addTag
Add one or more tags to the current installation object stored by WonderPush.Does nothing if called without required user consent.
- Parameters:
tag
- The tags to add to the installation.
-
removeTag
Remove one or more tags from the current installation object stored by WonderPush.Does nothing if called without required user consent.
- Parameters:
tag
- The tags to remove from the installation.
-
removeAllTags
public static void removeAllTags()Remove all tags from the current installation object stored by WonderPush.Does nothing if called without required user consent.
-
getTags
Returns all the tags of the current installation object stored by WonderPush.- Returns:
- A copy of the set of tags attached to the installation.
Never returns
null
.
-
hasTag
Test whether the current installation has the given tag attached to it.- Parameters:
tag
- The tag to test.- Returns:
true
if the given tag is attached to the installation,false
otherwise.
-
initialize
public static void initialize(android.content.Context context) Initialize WonderPush.Using automatic initialization, you do not need to take care of this yourself. You must otherwise call this method before using the SDK. A good place for that is in the
Application.onCreate()
of yourApplication
class.- Parameters:
context
- AndActivity
orApplication
context.
-
initialize
public static void initialize(android.content.Context context, String clientId, String clientSecret) Initialize WonderPush from yourWonderPushInitializer
implementation.Using automatic initialization, you do not need to take care of this yourself.
Prefer calling the simpler
initialize(Context)
function directly, as it will instantiate yourWonderPushInitializer
implementation which will in turn call this function. This way you concentrate the retrieval of your credentials from secure storage in a single location.- Parameters:
context
- The mainActivity
of your application, or failing that, theApplication
context.clientId
- The clientId of your application.clientSecret
- The clientSecret of your application.
-
setRequiresUserConsent
public static void setRequiresUserConsent(boolean value) Sets whether user consent is required before the SDK is allowed to work.Call this method before
initialize(Context)
.- Parameters:
value
- Whether user consent is required before the SDK is allowed to work.- See Also:
-
getUserConsent
public static boolean getUserConsent()Returns whether user consent has already provided consent.Call this method after
initialize(Context)
. -
setUserConsent
public static void setUserConsent(boolean value) Provides or withdraws user consent.Call this method after
initialize(Context)
.- Parameters:
value
- Whether the user provided or withdrew consent.- See Also:
-
downloadAllData
public static void downloadAllData()Exports all data stored locally and on WonderPush servers and then starts a sharing activity for the user to save it.This method is blocking.
-
clearEventsHistory
public static void clearEventsHistory()Ask the WonderPush servers to delete any event associated with the all local installations. -
clearPreferences
public static void clearPreferences()Ask the WonderPush servers to delete any custom data associated with the all local installations and related users. -
clearAllData
public static void clearAllData()Remove any local storage and ask the WonderPush servers to delete any data associated with the all local installations and related users. -
clearAll
public static void clearAll()Deprecated.Remove any local storage and ask the WonderPush servers to delete any data associated with the all local installations and related users.- See Also:
-
setUserId
Sets the user id, used to identify a single identity across multiple devices, and to correctly identify multiple users on a single device.If not called, the last used user id it assumed. Defaulting to
null
if none is known.Prefer calling this method just before calling
initialize(Context)
, rather than just after.Upon changing userId, the push token is wiped, so avoid unnecessary calls, like calling with
null
just before calling with a user id. Successive calls with the same userId are fine.Changing the user id is akin to loading a new profile. A new installation will be created and no tags, properties or events will be kept. For more information, see our documentation.
- Parameters:
userId
- The user id, unique to your application. Usenull
for anonymous users.
You are strongly encouraged to use your own unique internal identifier.
-
getUserId
Gets the user id, used to identify a single identity across multiple devices, and to correctly identify multiple users on a single device.You should not call this method before initializing the SDK.
- Returns:
- The user id, which may be
null
for anonymous users. - See Also:
-
getDeviceId
Gets the device id, used to identify a single device, and to correctly identify multiple users on a single device.You should not call this method before initializing the SDK.
Returns
null
if called without required user consent.- Returns:
- The device id, or
null
if the SDK is not initialized. - See Also:
-
getInstallationId
Gets the device id, used to identify a single device across applications, and to correctly identify multiple users on a single device.You should not call this method before the SDK is ready.
Returns
null
if called without required user consent.- Returns:
- The device id, or
null
if the SDK is not initialized.
-
getPushToken
Gets the push token, used to send notification to this installation.You should not call this method before initializing the SDK.
Returns
null
if called without required user consent.- Returns:
- The push token, or
null
if the installation is not yet registered to push notifications, or has not finished refreshing the push token after a forced update.
-
getAccessToken
Gets the access token, used to grant access to the current installation to the WonderPush REST API.You should not call this method before the SDK is ready.
This together with your client secret gives entire control to the current installation and the associated user, you should not disclose it unnecessarily.
Returns
null
if called without required user consent.- Returns:
- The access token, or
null
if the SDK is not initialized.
-
subscribeToNotifications
public static void subscribeToNotifications(boolean fallbackToSettings) Enables push notifications for the current device- Parameters:
fallbackToSettings
- Shows a dialog that leads user to the settings should he refuse the permission
-
subscribeToNotifications
public static void subscribeToNotifications()Enables push notifications for the current device.Does nothing if called without required user consent.
-
unsubscribeFromNotifications
public static void unsubscribeFromNotifications()Disables push notifications for the current device.Does nothing if called without required user consent.
-
isSubscribedToNotifications
public static boolean isSubscribedToNotifications()Returns whether push notification are enabled.Returns
false
if called without required user consent.- Returns:
true
by default as no explicit user permission is required, unless required user consent is lacking.
-
getNotificationEnabled
Deprecated.Returns whether push notification are enabled.Use
isSubscribedToNotifications()
instead.Returns
false
if called without required user consent.- Returns:
true
by default as no explicit user permission is required, unless required user consent is lacking.- See Also:
-
setNotificationEnabled
Deprecated.Sets whether to enable push notifications for the current device.Use
subscribeToNotifications()
orunsubscribeFromNotifications()
instead.Does nothing if called without required user consent.
- Parameters:
status
-false
to opt out of push notifications.- See Also:
-
setIntegrator
Sets the framework, library or wrapper used for integration. This method should not be used by the developer directly, only by components that facilitates the native SDK integration.- Parameters:
integrator
- Expected format is "some-component-1.2.3"
-
getDelegate
Returns the configured delegate, ornull
if none was set.- See Also:
-
setDelegate
Configures a delegate for tighter integration with the SDK.Call this method as early as possible, like just before calling
initialize(Context)
.- Parameters:
delegate
- The new delegate to use.- See Also:
-