Search in sources :

Example 11 with OSDeviceState

use of com.onesignal.OSDeviceState in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method testDeviceStateIsSubscribed.

@Test
public void testDeviceStateIsSubscribed() throws Exception {
    assertNull(OneSignal.getDeviceState());
    OneSignalInit();
    threadAndTaskWait();
    OSDeviceState device = OneSignal.getDeviceState();
    assertTrue(device.isSubscribed());
    fastColdRestartApp();
    ShadowNotificationManagerCompat.enabled = false;
    OneSignalInit();
    threadAndTaskWait();
    // Device is a snapshot, last value should not change
    assertTrue(device.isSubscribed());
    // Retrieve new user device
    assertFalse(OneSignal.getDeviceState().isSubscribed());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 12 with OSDeviceState

use of com.onesignal.OSDeviceState in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method testDeviceStateHasEmailId.

@Test
public void testDeviceStateHasEmailId() throws Exception {
    String testEmail = "test@onesignal.com";
    assertNull(OneSignal.getDeviceState());
    OneSignalInit();
    threadAndTaskWait();
    OSDeviceState device = OneSignal.getDeviceState();
    assertNull(device.getEmailUserId());
    OneSignal.setEmail(testEmail);
    threadAndTaskWait();
    // Device is a snapshot, last value should not change
    assertNull(device.getEmailUserId());
    // Retrieve new user device
    assertNotNull(OneSignal.getDeviceState().getEmailUserId());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 13 with OSDeviceState

use of com.onesignal.OSDeviceState in project OneSignal-Android-SDK by OneSignal.

the class SynchronizerIntegrationTests method shouldLogoutOfSMS.

@Test
public void shouldLogoutOfSMS() throws Exception {
    OneSignalInit();
    smsSetThenLogout();
    OSDeviceState deviceState = OneSignal.getDeviceState();
    assertNull(deviceState.getSMSUserId());
    assertNull(deviceState.getSMSNumber());
}
Also used : OSDeviceState(com.onesignal.OSDeviceState) Test(org.junit.Test)

Example 14 with OSDeviceState

use of com.onesignal.OSDeviceState in project OneSignal-Android-SDK by OneSignal.

the class MainActivityViewModel method setupSubscriptionSwitch.

private void setupSubscriptionSwitch() {
    OSDeviceState deviceState = OneSignal.getDeviceState();
    boolean isPermissionEnabled = deviceState != null && deviceState.areNotificationsEnabled();
    final boolean isSubscribed = deviceState != null && deviceState.isSubscribed();
    subscriptionSwitch.setEnabled(isPermissionEnabled);
    subscriptionSwitch.setChecked(isSubscribed);
    if (isPermissionEnabled) {
        subscriptionRelativeLayout.setOnClickListener(v -> {
            boolean isSubscribed1 = subscriptionSwitch.isChecked();
            subscriptionSwitch.setChecked(!isSubscribed1);
            OneSignal.disablePush(isSubscribed1);
        });
    } else {
        subscriptionRelativeLayout.setOnClickListener(v -> intentTo.notificationPermissions());
    }
    subscriptionSwitch.setOnClickListener(v -> {
        OneSignal.disablePush(!subscriptionSwitch.isChecked());
    });
}
Also used : OSDeviceState(com.onesignal.OSDeviceState)

Aggregations

OSDeviceState (com.onesignal.OSDeviceState)14 Test (org.junit.Test)12