use of android.app.NotificationChannel in project robolectric by robolectric.
the class ShadowNotificationManagerTest method deleteNotificationChannelGroup.
@Test
@Config(minSdk = Build.VERSION_CODES.O)
public void deleteNotificationChannelGroup() {
final String channelId = "channelId";
final String channelGroupId = "channelGroupId";
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(channelGroupId, "groupName"));
NotificationChannel channel = new NotificationChannel(channelId, "channelName", 1);
channel.setGroup(channelGroupId);
notificationManager.createNotificationChannel(channel);
assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse();
notificationManager.deleteNotificationChannelGroup(channelGroupId);
assertThat(shadowOf(notificationManager).getNotificationChannelGroup(channelGroupId)).isNull();
// Per documentation, deleting a channel group also deletes all associated channels.
assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isTrue();
}
use of android.app.NotificationChannel in project robolectric by robolectric.
the class ShadowNotificationManager method createNotificationChannel.
@Implementation(minSdk = Build.VERSION_CODES.O)
protected void createNotificationChannel(Object channel) {
String id = ReflectionHelpers.callInstanceMethod(channel, "getId");
// for more info.
if (deletedNotificationChannels.containsKey(id)) {
notificationChannels.put(id, deletedNotificationChannels.remove(id));
}
NotificationChannel existingChannel = (NotificationChannel) notificationChannels.get(id);
// for more info.
if (existingChannel != null) {
NotificationChannel newChannel = (NotificationChannel) channel;
existingChannel.setName(newChannel.getName());
existingChannel.setDescription(newChannel.getDescription());
if (newChannel.getImportance() < existingChannel.getImportance()) {
existingChannel.setImportance(newChannel.getImportance());
}
if (Strings.isNullOrEmpty(existingChannel.getGroup())) {
existingChannel.setGroup(newChannel.getGroup());
}
return;
}
notificationChannels.put(id, channel);
}
use of android.app.NotificationChannel in project ETSMobile-Android2 by ApplETS.
the class ETSFcmListenerService method sendNotification.
/**
* Create and show a simple notification containing the received FCM message.
*
* @param data FCM message received.
*/
private void sendNotification(Map<String, String> data) {
SecurePreferences securePreferences = new SecurePreferences(this);
Gson gson = new Gson();
String receivedNotifString = securePreferences.getString(Constants.RECEIVED_NOTIF, "");
ArrayList<MonETSNotification> receivedNotif = gson.fromJson(receivedNotifString, new TypeToken<ArrayList<MonETSNotification>>() {
}.getType());
if (receivedNotif == null) {
receivedNotif = new ArrayList<>();
}
MonETSNotification nouvelleNotification = getMonETSNotificationFromMap(data);
receivedNotif.add(nouvelleNotification);
int numberOfNotifications = receivedNotif.size();
Intent intent = new Intent(this, NotificationActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_ets);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = mNotificationManager.getNotificationChannel(Constants.DEFAULT_NOTIFICATION_CHANNEL_ID);
if (channel == null) {
// We could create multiple channels based on the notification but let's just create one for maintenance purposes.
String channelName = getString(R.string.fcm_fallback_notification_channel_label);
channel = new NotificationChannel(Constants.DEFAULT_NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, Constants.DEFAULT_NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.school_48).setColor(getResources().getColor(R.color.red)).setContentTitle(getString(R.string.ets)).setContentText(getString(R.string.new_notifications)).setContentIntent(pendingIntent).setLargeIcon(icon).setAutoCancel(true).setNumber(numberOfNotifications);
NotificationCompat.InboxStyle inBoxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
String bigContentTitle = getString(R.string.notification_content_title, numberOfNotifications + "", (numberOfNotifications == 1 ? "" : "s"), (numberOfNotifications == 1 ? "" : "s"));
inBoxStyle.setBigContentTitle(bigContentTitle);
String username = ApplicationManager.userCredentials.getUsername();
Spannable sb = new SpannableString(username);
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inBoxStyle.setSummaryText(sb);
securePreferences.edit().putString(Constants.RECEIVED_NOTIF, gson.toJson(receivedNotif)).commit();
int minimumIndex = receivedNotif.size() - NUMBER_OF_NOTIF_TO_DISPLAY;
minimumIndex = minimumIndex < 0 ? 0 : minimumIndex;
for (int i = receivedNotif.size() - 1; i >= minimumIndex; i--) {
inBoxStyle.addLine(receivedNotif.get(i).getNotificationTexte());
}
if (numberOfNotifications > NUMBER_OF_NOTIF_TO_DISPLAY) {
int plusOthers = (numberOfNotifications - NUMBER_OF_NOTIF_TO_DISPLAY);
String plusOthersString = getString(R.string.others_notifications, plusOthers + "", (plusOthers == 1 ? "" : "s"));
Spannable others = new SpannableString(plusOthersString);
others.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, others.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
inBoxStyle.addLine(others);
}
mBuilder.setStyle(inBoxStyle);
mNotificationManager.notify(1, mBuilder.build());
}
use of android.app.NotificationChannel in project cordova-plugin-local-notifications by katzer.
the class Manager method createDefaultChannel.
/**
* TODO: temporary
*/
@SuppressLint("WrongConstant")
private void createDefaultChannel() {
NotificationManager mgr = getNotMgr();
if (SDK_INT < O)
return;
NotificationChannel channel = mgr.getNotificationChannel(CHANNEL_ID);
if (channel != null)
return;
channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_DEFAULT);
mgr.createNotificationChannel(channel);
}
use of android.app.NotificationChannel in project Douya by DreaminginCodeZH.
the class SendBroadcastWriter method createNotificationChannel.
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}
Context context = getContext();
String channelName = context.getString(Notifications.Channels.SEND_BROADCAST.NAME_RES);
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(Notifications.Channels.SEND_BROADCAST.ID, channelName, Notifications.Channels.SEND_BROADCAST.IMPORTANCE);
String channelDescription = context.getString(Notifications.Channels.SEND_BROADCAST.DESCRIPTION_RES);
channel.setDescription(channelDescription);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
}
Aggregations