java.lang.Object | |
↳ | com.wonderpush.sdk.WonderPush |
Main class of the WonderPush SDK.
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.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | INTENT_INTIALIZED | Local intent broadcasted when the WonderPush SDK has been initialized and network is reachable. | |||||||||
String | INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_ACTION | Intent action for notification button action `method`. | |||||||||
String | INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_AUTHORITY | Intent authority for notification button action `method`. | |||||||||
String | INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_EXTRA_ARG | Intent query parameter key for the notification button action `method` argument. | |||||||||
String | INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_EXTRA_METHOD | Intent query parameter key for the notification button action `method` method name. | |||||||||
String | INTENT_NOTIFICATION_BUTTON_ACTION_METHOD_SCHEME | Intent scheme for notification button action `method`. | |||||||||
String | INTENT_NOTIFICATION_OPENED | Local intent broadcasted when a push notification created by the WonderPush SDK has been opened. | |||||||||
String | 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 a INTENT_NOTIFICATION_OPENED intent. |
|||||||||
String | INTENT_NOTIFICATION_OPENED_EXTRA_RECEIVED_PUSH_NOTIFICATION | The extra key for the original received push notification intent in a INTENT_NOTIFICATION_OPENED intent. |
|||||||||
String | 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. | |||||||||
String | INTENT_NOTIFICATION_WILL_OPEN_EXTRA_AUTOMATIC_OPEN | The extra key denoting whether to automatically display a rich notification message in a INTENT_NOTIFICATION_WILL_OPEN intent. |
|||||||||
String | 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 a INTENT_NOTIFICATION_WILL_OPEN intent. |
|||||||||
String | INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE | The extra key denoting the received push notification type, for a INTENT_NOTIFICATION_WILL_OPEN intent. |
|||||||||
String | INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE_DATA | The value associated to data push notifications (aka silent notifications), corresponding to the extra key
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE . |
|||||||||
String | INTENT_NOTIFICATION_WILL_OPEN_EXTRA_RECEIVED_PUSH_NOTIFICATION | The extra key for the original received push notification intent in a INTENT_NOTIFICATION_WILL_OPEN intent. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static String |
getDeviceId()
Gets the device id, used to identify a single device across applications,
and to correctly identify multiple users on a single device.
| ||||||||||
static String |
getInstallationId()
Gets the device id, used to identify a single device across applications,
and to correctly identify multiple users on a single device.
| ||||||||||
static boolean | getNotificationEnabled() | ||||||||||
static String |
getPushToken()
Gets the push token, used to send notification to this installation.
| ||||||||||
static String |
getUserId()
Gets the user id, used to identify a single identity across multiple devices,
and to correctly identify multiple users on a single device.
| ||||||||||
static void |
initialize(Context context, String clientId, String clientSecret)
Initialize WonderPush from your
WonderPushInitializer implementation. | ||||||||||
static void |
initialize(Context context)
Initialize WonderPush.
| ||||||||||
static boolean |
isReady()
Whether the SDK is ready to operate and
the
INTENT_INTIALIZED intent has been dispatched. | ||||||||||
static boolean |
onBroadcastReceived(Context context, Intent intent, int iconResource, Class<? extends Activity> activityClass)
Method to be called in your own Google Cloud Messaging
BroadcastReceiver
to handle WonderPush push notifications.
| ||||||||||
synchronized static void |
putInstallationCustomProperties(JSONObject customProperties)
Update the custom properties attached to the current installation object stored by WonderPush.
| ||||||||||
static void | setLogging(boolean enable) | ||||||||||
static void | setNotificationEnabled(boolean status) | ||||||||||
static void |
setUserId(String userId)
Sets the user id, used to identify a single identity across multiple devices,
and to correctly identify multiple users on a single device.
| ||||||||||
static boolean |
showPotentialNotification(Activity activity, Intent intent)
Method to call on your
onNewIntent() and onCreate() methods to handle the WonderPush notification. | ||||||||||
static void |
trackEvent(String type)
Send an event to be tracked to WonderPush.
| ||||||||||
static void |
trackEvent(String type, JSONObject customData)
Send an event to be tracked to WonderPush.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Local intent broadcasted when the WonderPush SDK has been initialized and network is reachable.
Intent action for notification button action `method`.
Intent authority for notification button action `method`.
Intent query parameter key for the notification button action `method` argument.
Intent query parameter key for the notification button action `method` method name.
Intent scheme for notification button action `method`.
Local intent broadcasted when a push notification created by the WonderPush SDK has been opened.
The extra key for whether the user clicked the notification or it was automatically opened by the SDK
in a INTENT_NOTIFICATION_OPENED
intent.
The extra key for the original received push notification intent in a INTENT_NOTIFICATION_OPENED
intent.
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 handle data
notifications or any deep linking yourself.
The extra key denoting whether to automatically display a rich notification message in a INTENT_NOTIFICATION_WILL_OPEN
intent.
You can set this property to false
in your BroadcastReceiver.
The extra key for whether the user clicked the notification or it was automatically opened by the SDK
in a INTENT_NOTIFICATION_WILL_OPEN
intent.
The extra key denoting the received push notification type, for a INTENT_NOTIFICATION_WILL_OPEN
intent.
You can test this property against INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE_DATA
in your BroadcastReceiver.
The value associated to data push notifications (aka silent notifications), corresponding to the extra key
INTENT_NOTIFICATION_WILL_OPEN_EXTRA_NOTIFICATION_TYPE
.
The extra key for the original received push notification intent in a INTENT_NOTIFICATION_WILL_OPEN
intent.
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 initializing the SDK.
Because of the way our device id is build, it is populated asynchronously,
so you may get a null
response even a few moments after calling
initialize(Context)
.
You can either wait a bit (1 second should be enough on modern devices), or
wait for isReady()
to return true
, which may take some more
time on the first launch, especially is the network connection is bad.
null
if the SDK is not initialized.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.
null
if the SDK is not initialized.Gets the push token, used to send notification to this installation.
You should not call this method before initializing the SDK.
null
if the installation is not yet
registered to push notifications, or has not finished refreshing
the push token after a forced update.
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.
null
for anonymous users.Initialize WonderPush from your WonderPushInitializer
implementation.
Prefer calling the simpler initialize(Context)
function directly, as it will
instantiate your WonderPushInitializer
implementation which will in turn call this function.
This way you concentrate the retrieval of your credentials from secure storage in a single location.
context | The main Activity of your application, or failing that, the Application context.
It must be the same activity that you declared in the <meta-data> tag
under the WonderPush <receiver> tag in your AndroidManifest.xml . |
---|---|
clientId | The clientId of your application. |
clientSecret | The clientSecret of your application. |
Initialize WonderPush.
Call this method before using WonderPush.
A good place to initialize WonderPush is in your main activity's
onCreate(Bundle)
method as follows:
protected void onCreate(Bundle savedInstance) {
WonderPush.initialize(this);
}
This function will instantiate the WonderPushInitializer
implementation you provided in your
AndroidManifest.xml
.
Please look at that interface documentation for detailed instruction.
context | The main Activity of your application, or failing that, the Application context.
It must be the same activity that you declared in the <meta-data> tag
under the WonderPush <receiver> tag in your AndroidManifest.xml .
|
---|
Whether the SDK is ready to operate and
the INTENT_INTIALIZED
intent has been dispatched.
The SDK is ready when it is initialized and has fetched an access token.
Method to be called in your own Google Cloud Messaging BroadcastReceiver to handle WonderPush push notifications.
Note: There is no need to call this method if you use WonderPushBroadcastReceiver
,
as advertised in the guide.
Implement your BroadcastReceiver.onReceive(Context, Intent) method as follows:
public void onReceive(Context context, Intent intent) {
if (WonderPush.onBroadcastReceived(context, intent, R.drawable.icon, YourMainActivity.class)) {
return;
}
// Do your own handling here
}
For more information about Google Cloud Messaging visit: http://developer.android.com/google/gcm/index.html.
context | The current context. |
---|---|
intent | The received intent. |
iconResource | The icon you want to show in the notification. |
activityClass | The activity class you want to start when the user touches the notification |
true
if handled, false
otherwise.
Update the custom 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.
customProperties | The partial object containing only the properties to update. |
---|
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 access token is wiped, so avoid unnecessary calls, like calling with null
just before calling with a user id.
userId | The user id, unique to your application.
Use null for anonymous users.You are strongly encouraged to use your own unique internal identifier. |
---|
Method to call on your onNewIntent()
and onCreate()
methods to handle the WonderPush notification.
Starting from API 14, there is no need to call this method, but it won't hurt if you do.
This method is automatically called from within initialize(Context)
,
so calling this method after calling initialize(Context)
is useless.
Example:
@Override
protected void onCreate(Bundle savedInstance) {
// In case you call WonderPush.initialize() from your custom Application class,
// and you target API < 14, you can either call WonderPush.initialize() once again here
// or call this method instead.
WonderPush.showPotentialNotification(this, getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
WonderPush.showPotentialNotification(this, intent);
}
activity | The current Activity .
Just give this . |
---|---|
intent | The intent the activity received.
Just give the intent you received in parameter, or give getIntent() . |
true
if handled, false
otherwise.
Send an event to be tracked to WonderPush.
type | The event type, or name.
Event types starting with an @ character are reserved.
|
---|
Send an event to be tracked to WonderPush.
type | The event type, or name.
Event types starting with an @ character are reserved. |
---|---|
customData | A JSON object containing custom properties to be attached to the event. Prefer using a few custom properties over a plethora of event type variants. |