Search in sources :

Example 1 with NotificationChannelManager_createNotificationChannel

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

the class NotificationChannelManagerRunner method createNotificationChannelCreateBasicChannel.

@Test
public void createNotificationChannelCreateBasicChannel() throws Exception {
    JSONObject payload = new JSONObject();
    JSONObject chnl = new JSONObject();
    chnl.put("id", "test_id");
    payload.put("chnl", chnl.toString());
    String ret = NotificationChannelManager_createNotificationChannel(blankActivity, payload);
    NotificationChannel channel = ShadowRoboNotificationManager.lastChannel;
    assertEquals("test_id", ret);
    assertEquals("test_id", ShadowRoboNotificationManager.lastChannel.getId());
    assertNotNull(channel.getSound());
    assertTrue(channel.shouldShowLights());
    assertTrue(channel.shouldVibrate());
}
Also used : NotificationChannelManager_createNotificationChannel(com.onesignal.OneSignalPackagePrivateHelper.NotificationChannelManager_createNotificationChannel) NotificationChannel(android.app.NotificationChannel) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 2 with NotificationChannelManager_createNotificationChannel

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

the class NotificationChannelManagerRunner method createNotificationChannelWithALlOptions.

@Test
public void createNotificationChannelWithALlOptions() throws Exception {
    JSONObject payload = new JSONObject();
    JSONObject chnl = new JSONObject();
    chnl.put("id", "test_id");
    chnl.put("nm", "Test Name");
    chnl.put("dscr", "Some description");
    chnl.put("grp_id", "grp_id");
    chnl.put("grp_nm", "Group Name");
    payload.put("pri", 10);
    payload.put("led", 0);
    payload.put("ledc", "FFFF0000");
    payload.put("vib", 0);
    payload.put("vib_pt", new JSONArray("[1,2,3,4]"));
    payload.put("sound", "notification");
    payload.put("vis", Notification.VISIBILITY_SECRET);
    payload.put("bdg", 1);
    payload.put("bdnd", 1);
    payload.put("chnl", chnl.toString());
    String ret = NotificationChannelManager_createNotificationChannel(blankActivity, payload);
    NotificationChannel channel = ShadowRoboNotificationManager.lastChannel;
    assertEquals("test_id", ret);
    assertEquals("test_id", ShadowRoboNotificationManager.lastChannel.getId());
    assertEquals("Test Name", channel.getName());
    assertEquals("Some description", channel.getDescription());
    assertEquals("grp_id", channel.getGroup());
    NotificationChannelGroup group = ShadowRoboNotificationManager.lastChannelGroup;
    assertEquals("grp_id", group.getId());
    assertEquals("Group Name", group.getName());
    assertNotNull(channel.getSound());
    // Setting a led color should NOT override enableLights
    assertFalse(channel.shouldShowLights());
    assertEquals(-65536, channel.getLightColor());
    // Setting a pattern should NOT override enableVibration
    assertFalse(channel.shouldVibrate());
    assertArrayEquals(new long[] { 1, 2, 3, 4 }, channel.getVibrationPattern());
    assertEquals(NotificationManager.IMPORTANCE_MAX, channel.getImportance());
    assertEquals("content://settings/system/notification_sound", channel.getSound().toString());
    assertEquals(Notification.VISIBILITY_SECRET, channel.getLockscreenVisibility());
    assertTrue(channel.canShowBadge());
    assertTrue(channel.canBypassDnd());
}
Also used : NotificationChannelManager_createNotificationChannel(com.onesignal.OneSignalPackagePrivateHelper.NotificationChannelManager_createNotificationChannel) NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 3 with NotificationChannelManager_createNotificationChannel

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

the class NotificationChannelManagerRunner method handleInvalidColorCode.

@Test
@Config(shadows = { ShadowOneSignal.class })
public void handleInvalidColorCode() throws Exception {
    JSONObject payload = new JSONObject();
    JSONObject chnl = new JSONObject();
    chnl.put("id", "test_id");
    chnl.put("nm", "Test Name");
    payload.put("ledc", "FFFFFFFFY");
    payload.put("chnl", chnl.toString());
    NotificationChannelManager_createNotificationChannel(blankActivity, payload);
    // check default to white
    NotificationChannel channel = ShadowRoboNotificationManager.lastChannel;
    BigInteger ledColor = new BigInteger("FFFFFFFF", 16);
    assertEquals(ledColor.intValue(), channel.getLightColor());
    assertTrue(ShadowOneSignal.messages.contains("OneSignal LED Color Settings: ARGB Hex value incorrect format (E.g: FF9900FF)"));
}
Also used : NotificationChannelManager_createNotificationChannel(com.onesignal.OneSignalPackagePrivateHelper.NotificationChannelManager_createNotificationChannel) NotificationChannel(android.app.NotificationChannel) JSONObject(org.json.JSONObject) BigInteger(java.math.BigInteger) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 4 with NotificationChannelManager_createNotificationChannel

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

the class NotificationChannelManagerRunner method createNotificationChannelShouldReturnDefaultChannelWithEmptyPayload.

@Test
public void createNotificationChannelShouldReturnDefaultChannelWithEmptyPayload() {
    JSONObject payload = new JSONObject();
    String ret = NotificationChannelManager_createNotificationChannel(blankActivity, payload);
    assertEquals("fcm_fallback_notification_channel", ret);
    NotificationChannel lastChannel = ShadowRoboNotificationManager.lastChannel;
    assertEquals("fcm_fallback_notification_channel", lastChannel.getId());
    assertNotNull(lastChannel.getSound());
    assertTrue(lastChannel.shouldShowLights());
    assertTrue(lastChannel.shouldVibrate());
}
Also used : NotificationChannelManager_createNotificationChannel(com.onesignal.OneSignalPackagePrivateHelper.NotificationChannelManager_createNotificationChannel) NotificationChannel(android.app.NotificationChannel) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

NotificationChannel (android.app.NotificationChannel)4 NotificationChannelManager_createNotificationChannel (com.onesignal.OneSignalPackagePrivateHelper.NotificationChannelManager_createNotificationChannel)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 NotificationChannelGroup (android.app.NotificationChannelGroup)1 BigInteger (java.math.BigInteger)1 JSONArray (org.json.JSONArray)1 Config (org.robolectric.annotation.Config)1