Search in sources :

Example 1 with MobileMessagingCore

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();
}
Also used : MobileMessagingCore(org.infobip.mobile.messaging.MobileMessagingCore)

Example 2 with MobileMessagingCore

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;
}
Also used : NotificationHandler(org.infobip.mobile.messaging.notification.NotificationHandler) AndroidBroadcaster(org.infobip.mobile.messaging.platform.AndroidBroadcaster) MobileMessagingCore(org.infobip.mobile.messaging.MobileMessagingCore)

Example 3 with MobileMessagingCore

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()]));
}
Also used : MessageStore(org.infobip.mobile.messaging.storage.MessageStore) Message(org.infobip.mobile.messaging.Message) MobileMessagingCore(org.infobip.mobile.messaging.MobileMessagingCore)

Aggregations

MobileMessagingCore (org.infobip.mobile.messaging.MobileMessagingCore)3 Message (org.infobip.mobile.messaging.Message)1 NotificationHandler (org.infobip.mobile.messaging.notification.NotificationHandler)1 AndroidBroadcaster (org.infobip.mobile.messaging.platform.AndroidBroadcaster)1 MessageStore (org.infobip.mobile.messaging.storage.MessageStore)1