Search in sources :

Example 81 with NotificationChannel

use of android.app.NotificationChannel 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 82 with NotificationChannel

use of android.app.NotificationChannel 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)

Example 83 with NotificationChannel

use of android.app.NotificationChannel in project routerkeygenAndroid by routerkeygen.

the class NotificationUtils method initChannels.

static void initChannels(Context context) {
    if (Build.VERSION.SDK_INT < 26 || channelCreated) {
        return;
    }
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel(NotificationCompat.CATEGORY_SERVICE, context.getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription("Channel description");
    if (notificationManager != null) {
        notificationManager.createNotificationChannel(channel);
    }
    channelCreated = true;
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager)

Example 84 with NotificationChannel

use of android.app.NotificationChannel in project robolectric by robolectric.

the class ShadowNotificationManagerTest method createNotificationChannel.

@Test
@Config(minSdk = Build.VERSION_CODES.O)
public void createNotificationChannel() {
    notificationManager.createNotificationChannel(new NotificationChannel("id", "name", 1));
    assertThat(shadowOf(notificationManager).getNotificationChannels()).hasSize(1);
    NotificationChannel channel = (NotificationChannel) shadowOf(notificationManager).getNotificationChannel("id");
    assertThat(channel.getName().toString()).isEqualTo("name");
    assertThat(channel.getImportance()).isEqualTo(1);
}
Also used : NotificationChannel(android.app.NotificationChannel) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 85 with NotificationChannel

use of android.app.NotificationChannel in project robolectric by robolectric.

the class ShadowNotificationManagerTest method createNotificationChannel_updateChannel.

@Test
@Config(minSdk = Build.VERSION_CODES.O)
public void createNotificationChannel_updateChannel() {
    NotificationChannel channel = new NotificationChannel("id", "name", 1);
    channel.setDescription("description");
    channel.setGroup("channelGroupId");
    channel.setLightColor(7);
    NotificationChannel channelUpdate = new NotificationChannel("id", "newName", 2);
    channelUpdate.setDescription("newDescription");
    channelUpdate.setGroup("newChannelGroupId");
    channelUpdate.setLightColor(15);
    notificationManager.createNotificationChannel(channel);
    notificationManager.createNotificationChannel(channelUpdate);
    assertThat(shadowOf(notificationManager).getNotificationChannels()).hasSize(1);
    NotificationChannel resultChannel = (NotificationChannel) shadowOf(notificationManager).getNotificationChannel("id");
    assertThat(resultChannel.getName().toString()).isEqualTo("newName");
    assertThat(resultChannel.getDescription()).isEqualTo("newDescription");
    // No importance upgrade.
    assertThat(resultChannel.getImportance()).isEqualTo(1);
    // No group resultChannel.
    assertThat(resultChannel.getGroup()).isEqualTo("channelGroupId");
    // Other settings are unchanged as well.
    assertThat(resultChannel.getLightColor()).isEqualTo(7);
}
Also used : NotificationChannel(android.app.NotificationChannel) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

NotificationChannel (android.app.NotificationChannel)762 Test (org.junit.Test)430 NotificationBackend (com.android.settings.notification.NotificationBackend)215 NotificationManager (android.app.NotificationManager)210 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)114 Intent (android.content.Intent)87 Preference (androidx.preference.Preference)76 PendingIntent (android.app.PendingIntent)73 NotificationChannelGroup (android.app.NotificationChannelGroup)54 NotificationCompat (android.support.v4.app.NotificationCompat)45 Notification (android.app.Notification)43 ArrayList (java.util.ArrayList)34 TargetApi (android.annotation.TargetApi)32 AudioAttributes (android.media.AudioAttributes)31 RequiresApi (android.support.annotation.RequiresApi)28 RequiresApi (androidx.annotation.RequiresApi)25 Uri (android.net.Uri)21 RestrictedListPreference (com.android.settings.RestrictedListPreference)20 SuppressLint (android.annotation.SuppressLint)19 ShortcutInfo (android.content.pm.ShortcutInfo)19