Display Engagement

Steps to activate and display a new GeoPush engagement

You can display engagements triggered by the GeoPush service. Just add the below code in you Activity in the GeoSDK.

If you're like us, itching to skip this guide and get your hands on the sample code, we have a sample project just for you. Feel free to clone on Github.

private Context mContext = null;
private Moments mMomentsClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Do something of your insterest.
mContext = this;
initializeLotaDataSDK();
}
private void initializeLotaDataSDK() {
mMomentsClient = MomentsClient.getInstance(this) {
trackEngagements();
}
protected void trackEngagements() {
//Receiver that handles notification. Provide the desired id, icon and ringtone for your notifications.
NotificationReceiver notificationReceiver = new NotificationReceiver(
101, R.drawable.lotadata_notification_icon, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) {
/**
* Method called when user clicks on notification
* @param context The Context in which the receiver is running.
* @param actionText String representing the text specified during engagement creation.
* @param actionLink String representing the url link specified during engagement creation.
* @param actionLink String representing the notification message.
*/
@Override
public void notificationClicked(Context context, String actionText, String actionLink, String message) {
/*
!!! Notice that actionLink can be an URL or a class (depends on how the campaign was configured). !!!
!!! You should check the content before go ahead !!!
*/
//For ilustration purporses.
if(actionLink.contains("http") || actionLink.contains("https")) {//Is it a url link?
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(actionLink));
browserIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
//Launch a browser
context.startActivity(browserIntent);
} else if (actionLink.contains(context.getPackageName())){//Is it an Activity class?
try {
Class activityClass = Class.forName(actionLink);
Intent myIntent = new Intent(context, activityClass);
myIntent.putExtra(Moments.LD_NOTIFICATION_ACTION_TEXT, actionText);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Launch an internal activity
context.startActivity(myIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
};
mMomentsClient.trackEngagements(notificationReceiver);
}
protected void untrackEngagements() {
if(mMomentsClient != null) mMomentsClient.untrackEngagements();
}
@Override
protected void onDestroy() {
if (mMomentsClient != null) {
untrackEngagements();
mMomentsClient.disconnect();
}
super.onDestroy();
}

Questions?

We are eager to hear from you and happy to share best practices for integrating the SDK. There are many ways for you to reach us:

But first, please sign up for an account and download our SDK.