Skip to content

Instantly share code, notes, and snippets.

@aditrioka
Last active August 9, 2019 08:30
Show Gist options
  • Save aditrioka/f45caa2a2b78c0978ec7fb19e825128b to your computer and use it in GitHub Desktop.
Save aditrioka/f45caa2a2b78c0978ec7fb19e825128b to your computer and use it in GitHub Desktop.
application class where we initialize moengage
// we initialize moengage in applicaiton class
public class StudentApplication {
@Override
public void onCreate() {
super.onCreate();
setupMoengage();
}
private void setupMoengage() {
MoEngage moEngage = new MoEngage.Builder(this, getString(R.string.MOENGAGE_APP_ID))
.setLogLevel(Logger.VERBOSE)
.setNotificationSmallIcon((
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
R.drawable.ic_notification_small : R.drawable.ic_stat_onesignal_default))
.setNotificationType(R.integer.notification_type_multiple)
.setNotificationTone("rg_sound")
.enableLocationServices()
.build();
MoEngage.initialise(moEngage);
trackInstallOrUpdate();
PushManager.getInstance().setTokenObserver(new TokenReceivedListener(this));
PushManager.getInstance().setMessageListener(new CustomPushMessageListener());
}
/**
* Tell MoEngage SDK whether the user is a new user of the application or an existing user.
*/
private void trackInstallOrUpdate() {
//keys are just sample keys, use suitable keys for the apps
SharedPreferences preferences = getSharedPreferences("rgmoengage", Context.MODE_PRIVATE);
boolean existing = false;
if (preferences.getBoolean("has_sent_install", false)) {
if (preferences.getBoolean("existing", false)) {
existing = true;
}
MoEHelper.getInstance(getApplicationContext()).setExistingUser(existing);
preferences.edit().putBoolean("has_sent_install", true).apply();
preferences.edit().putBoolean("existing", true).apply();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment