Search in sources :

Example 1 with MobileMessagingError

use of org.infobip.mobile.messaging.mobile.MobileMessagingError in project mobile-messaging-sdk-android by infobip.

the class AndroidBroadcasterTest method test_should_send_error.

@Test
public void test_should_send_error() throws Exception {
    // Given
    MobileMessagingError error = new MobileMessagingError("SomeCode", "SomeMessage");
    // When
    broadcastSender.error(error);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(Event.API_COMMUNICATION_ERROR.getKey(), intent.getAction());
    MobileMessagingError errorAfter = (MobileMessagingError) intent.getSerializableExtra(BroadcastParameter.EXTRA_EXCEPTION);
    assertJEquals(error, errorAfter);
}
Also used : Intent(android.content.Intent) MobileMessagingError(org.infobip.mobile.messaging.mobile.MobileMessagingError) Test(org.junit.Test)

Example 2 with MobileMessagingError

use of org.infobip.mobile.messaging.mobile.MobileMessagingError in project mobile-messaging-sdk-android by infobip.

the class MobileMessagingBroadcastReceiver method onApiCommunicationError.

void onApiCommunicationError(Context context, Intent intent) {
    MobileMessagingError mobileMessagingError = (MobileMessagingError) intent.getSerializableExtra(EXTRA_EXCEPTION);
    String errorDescription = mobileMessagingError != null ? mobileMessagingError.getMessage() : context.getString(R.string.error_api_comm_unknown) + "\n";
    PreferenceManager.getDefaultSharedPreferences(context).edit().putString(ApplicationPreferences.LAST_API_COMMUNICATION_ERROR, errorDescription).apply();
}
Also used : MobileMessagingError(org.infobip.mobile.messaging.mobile.MobileMessagingError)

Example 3 with MobileMessagingError

use of org.infobip.mobile.messaging.mobile.MobileMessagingError in project mobile-messaging-sdk-android by infobip.

the class AndroidGeoBroadcasterTest method test_should_send_error.

@Test
public void test_should_send_error() throws Exception {
    // Given
    MobileMessagingError error = new MobileMessagingError("SomeCode", "SomeMessage");
    // When
    broadcastSender.error(error);
    // Then
    Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
    Intent intent = intentArgumentCaptor.getValue();
    assertEquals(Event.API_COMMUNICATION_ERROR.getKey(), intent.getAction());
    MobileMessagingError errorAfter = (MobileMessagingError) intent.getSerializableExtra(BroadcastParameter.EXTRA_EXCEPTION);
    assertJEquals(error, errorAfter);
}
Also used : Intent(android.content.Intent) MobileMessagingError(org.infobip.mobile.messaging.mobile.MobileMessagingError) Test(org.junit.Test)

Example 4 with MobileMessagingError

use of org.infobip.mobile.messaging.mobile.MobileMessagingError in project mobile-messaging-sdk-android by infobip.

the class MainActivity method onMSISDNPreferenceChanged.

private void onMSISDNPreferenceChanged(SharedPreferences sharedPreferences) {
    Long msisdn = null;
    try {
        if (sharedPreferences.contains(ApplicationPreferences.MSISDN)) {
            msisdn = Long.parseLong(sharedPreferences.getString(ApplicationPreferences.MSISDN, "0"));
            if (msisdn <= 0) {
                throw new IllegalArgumentException();
            }
        }
    } catch (Exception e) {
        showToast(R.string.toast_message_userdata_invalid);
        return;
    }
    if (msisdn != null) {
        UserData userData = new UserData();
        userData.setMsisdn(msisdn.toString());
        MobileMessaging.getInstance(this).syncUserData(userData, new MobileMessaging.ResultListener<UserData>() {

            @Override
            public void onResult(UserData result) {
                Log.v(TAG, "User data sync complete: " + result);
            }

            @Override
            public void onError(MobileMessagingError e) {
                Log.e(TAG, String.format(Locale.getDefault(), "User data sync error message: %s, code: %s" + e.getMessage(), e.getCode()));
            }
        });
    }
}
Also used : MobileMessaging(org.infobip.mobile.messaging.MobileMessaging) UserData(org.infobip.mobile.messaging.UserData) MobileMessagingError(org.infobip.mobile.messaging.mobile.MobileMessagingError)

Aggregations

MobileMessagingError (org.infobip.mobile.messaging.mobile.MobileMessagingError)4 Intent (android.content.Intent)2 Test (org.junit.Test)2 MobileMessaging (org.infobip.mobile.messaging.MobileMessaging)1 UserData (org.infobip.mobile.messaging.UserData)1