use of org.infobip.mobile.messaging.MobileMessagingCore in project mobile-messaging-sdk-android by infobip.
the class RegistrationTokenHandler method sendRegistrationToServer.
/**
* Persist registration to third-party servers.
* <p>
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(Context context, String token) {
if (StringUtils.isBlank(token)) {
return;
}
MobileMessagingCore mobileMessagingCore = MobileMessagingCore.getInstance(context);
String infobipRegistrationId = mobileMessagingCore.getPushRegistrationId();
boolean saveNeeded = null == infobipRegistrationId || null == mobileMessagingCore.getCloudToken() || !token.equals(mobileMessagingCore.getCloudToken()) || !mobileMessagingCore.isRegistrationIdReported();
if (saveNeeded) {
mobileMessagingCore.setRegistrationId(token);
}
mobileMessagingCore.sync();
}
use of org.infobip.mobile.messaging.MobileMessagingCore in project mobile-messaging-sdk-android by infobip.
the class MobileMessagingGcmIntentService method mobileMessageHandler.
private MobileMessageHandler mobileMessageHandler() {
if (mobileMessageHandler == null) {
MobileMessagingCore mobileMessagingCore = MobileMessagingCore.getInstance(this);
NotificationHandler notificationHandler = mobileMessagingCore.getNotificationHandler();
mobileMessageHandler = new MobileMessageHandler(mobileMessagingCore, new AndroidBroadcaster(this), notificationHandler, mobileMessagingCore.getMessageStoreWrapper());
}
return mobileMessageHandler;
}
use of org.infobip.mobile.messaging.MobileMessagingCore in project mobile-messaging-sdk-android by infobip.
the class GeoAreasHandler method updateMessageStoreWithReportingResult.
/**
* Updates ids of existing messages based on reporting result.
* </p> Does nothing if message store is not enabled.
*
* @param reportingResult geo reporting result that contains mapping for new message ids
*/
private static void updateMessageStoreWithReportingResult(Context context, @NonNull GeoReportingResult reportingResult) {
if (reportingResult.getMessageIds() == null || reportingResult.getMessageIds().isEmpty()) {
return;
}
MobileMessagingCore mobileMessagingCore = MobileMessagingCore.getInstance(context);
if (!mobileMessagingCore.isMessageStoreEnabled()) {
return;
}
MessageStore messageStore = mobileMessagingCore.getMessageStore();
// Code below is far from being effective but messageId is primary key
// so we will have to remove messages with invalid keys
List<Message> allMessages = messageStore.findAll(context);
Map<String, String> messageIds = reportingResult.getMessageIds();
for (Message message : allMessages) {
String newMessageId = messageIds.get(message.getMessageId());
if (newMessageId == null) {
continue;
}
message.setMessageId(newMessageId);
}
messageStore.deleteAll(context);
messageStore.save(context, allMessages.toArray(new Message[allMessages.size()]));
}
Aggregations