Java Code Examples for android.app.NotificationChannel#getId()
The following examples show how to use
android.app.NotificationChannel#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationChannels.java From xDrip with GNU General Public License v3.0 | 6 votes |
@TargetApi(26) private static int myhashcode(NotificationChannel x) { int result = x.getId() != null ? x.getId().hashCode() : 0; //result = 31 * result + (getName() != null ? getName().hashCode() : 0); //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); //result = 31 * result + getImportance(); //result = 31 * result + (mBypassDnd ? 1 : 0); //result = 31 * result + getLockscreenVisibility(); result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0); //result = 31 * result + (x.mLights ? 1 : 0); result = 31 * result + x.getLightColor(); result = 31 * result + Arrays.hashCode(x.getVibrationPattern()); //result = 31 * result + getUserLockedFields(); //result = 31 * result + (mVibrationEnabled ? 1 : 0); //result = 31 * result + (mShowBadge ? 1 : 0); //result = 31 * result + (isDeleted() ? 1 : 0); //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0); //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0); //result = 31 * result + (isBlockableSystem() ? 1 : 0); return result; }
Example 2
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@TargetApi(26) private static int myhashcode(NotificationChannel x) { int result = x.getId() != null ? x.getId().hashCode() : 0; //result = 31 * result + (getName() != null ? getName().hashCode() : 0); //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0); //result = 31 * result + getImportance(); //result = 31 * result + (mBypassDnd ? 1 : 0); //result = 31 * result + getLockscreenVisibility(); result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0); //result = 31 * result + (x.mLights ? 1 : 0); result = 31 * result + x.getLightColor(); result = 31 * result + Arrays.hashCode(x.getVibrationPattern()); //result = 31 * result + getUserLockedFields(); //result = 31 * result + (mVibrationEnabled ? 1 : 0); //result = 31 * result + (mShowBadge ? 1 : 0); //result = 31 * result + (isDeleted() ? 1 : 0); //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0); //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0); //result = 31 * result + (isBlockableSystem() ? 1 : 0); return result; }
Example 3
Source File: NotificationUtil.java From AppUpdate with Apache License 2.0 | 5 votes |
/** * 获取设置的通知渠道id * * @return 如果没有设置则使用默认的 'appUpdate' */ @RequiresApi(api = Build.VERSION_CODES.O) private static String getNotificationChannelId() { NotificationChannel channel = requireManagerNotNull().getNotificationChannel(); if (channel == null) { return Constant.DEFAULT_CHANNEL_ID; } String channelId = channel.getId(); if (TextUtils.isEmpty(channelId)) { return Constant.DEFAULT_CHANNEL_ID; } return channelId; }
Example 4
Source File: NotificationUtil.java From AppUpdate with Apache License 2.0 | 5 votes |
/** * 获取设置的通知渠道id * * @return 如果没有设置则使用默认的 'appUpdate' */ @RequiresApi(api = Build.VERSION_CODES.O) private static String getNotificationChannelId() { NotificationChannel channel = requireManagerNotNull().getNotificationChannel(); if (channel == null) { return Constant.DEFAULT_CHANNEL_ID; } String channelId = channel.getId(); if (TextUtils.isEmpty(channelId)) { return Constant.DEFAULT_CHANNEL_ID; } return channelId; }
Example 5
Source File: MyService.java From BadgeForAppIcon with MIT License | 5 votes |
private void sendIconNumNotification() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (nm == null) return; String notificationChannelId = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel notificationChannel = createNotificationChannel(); nm.createNotificationChannel(notificationChannel); notificationChannelId = notificationChannel.getId(); } Notification notification = null; try { notification = new NotificationCompat.Builder(this, notificationChannelId) .setSmallIcon(getApplicationInfo().icon) .setWhen(System.currentTimeMillis()) .setContentTitle("title") .setContentText("content num: " + count) .setTicker("ticker") .setAutoCancel(true) .setNumber(count) .build(); notification = setIconBadgeNumManager.setIconBadgeNum(getApplication(), notification, count); nm.notify(32154, notification); } catch (Exception e) { e.printStackTrace(); } }
Example 6
Source File: MusicService.java From DMusic with Apache License 2.0 | 5 votes |
private NotificationCompat.Builder getNotification(Context context, @Nullable NotificationChannel channel) { NotificationCompat.Builder builder; if (channel != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { builder = new NotificationCompat.Builder(context, channel.getId()); } else { builder = new NotificationCompat.Builder(context, ""); } return builder; }
Example 7
Source File: NotificationHandler.java From syncthing-android with Mozilla Public License 2.0 | 5 votes |
private NotificationCompat.Builder getNotificationBuilder(NotificationChannel channel) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { return new NotificationCompat.Builder(mContext, channel.getId()); } else { //noinspection deprecation return new NotificationCompat.Builder(mContext); } }
Example 8
Source File: NotificationChannels.java From xDrip with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(NotificationCompat.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(wip.mNotification.vibrate); template.setSound(wip.mNotification.sound, generic_audio); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }
Example 9
Source File: NotificationChannels.java From xDrip with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(Notification.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(temp.vibrate); template.setSound(temp.sound, generic_audio); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }
Example 10
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(NotificationCompat.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(wip.mNotification.vibrate); template.setSound(wip.mNotification.sound, generic_audio); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(wip.mNotification.ledARGB); if ((wip.mNotification.ledOnMS != 0) && (wip.mNotification.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }
Example 11
Source File: NotificationChannels.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@TargetApi(26) public static NotificationChannel getChan(Notification.Builder wip) { final Notification temp = wip.build(); if (temp.getChannelId() == null) return null; // create generic audio attributes final AudioAttributes generic_audio = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .build(); // create notification channel for hashing purposes from the existing notification builder NotificationChannel template = new NotificationChannel( temp.getChannelId(), getString(temp.getChannelId()), NotificationManager.IMPORTANCE_DEFAULT); // mirror the notification parameters in the channel template.setGroup(temp.getChannelId()); template.setVibrationPattern(temp.vibrate); template.setSound(temp.sound, generic_audio); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // get a nice string to identify the hash final String mhash = my_text_hash(template); // create another notification channel using the hash because id is immutable final NotificationChannel channel = new NotificationChannel( template.getId() + mhash, getString(temp.getChannelId()) + mhash, NotificationManager.IMPORTANCE_DEFAULT); // mirror the settings from the previous channel channel.setSound(template.getSound(), generic_audio); if (addChannelGroup()) { channel.setGroup(template.getGroup()); } else { channel.setGroup(channel.getId()); } channel.setDescription(template.getDescription()); channel.setVibrationPattern(template.getVibrationPattern()); template.setLightColor(temp.ledARGB); if ((temp.ledOnMS != 0) && (temp.ledOffMS != 0)) template.enableLights(true); // weird how this doesn't work like vibration pattern template.setDescription(temp.getChannelId() + " " + wip.hashCode()); // create a group to hold this channel if one doesn't exist or update text getNotifManager().createNotificationChannelGroup(new NotificationChannelGroup(channel.getGroup(), getString(channel.getGroup()))); // create this channel if it doesn't exist or update text getNotifManager().createNotificationChannel(channel); return channel; }
Example 12
Source File: ReactNativeFirebaseMessagingService.java From react-native-azurenotificationhub with MIT License | 4 votes |
public static void createNotificationChannel(Context context) { if (notificationChannelID == null) { ReactNativeNotificationHubUtil notificationHubUtil = ReactNativeNotificationHubUtil.getInstance(); ReactNativeNotificationChannelBuilder builder = ReactNativeNotificationChannelBuilder.Factory.create(); if (notificationHubUtil.hasChannelName(context)) { builder.setName(notificationHubUtil.getChannelName(context)); } if (notificationHubUtil.hasChannelDescription(context)) { builder.setDescription(notificationHubUtil.getChannelDescription(context)); } if (notificationHubUtil.hasChannelImportance(context)) { builder.setImportance(notificationHubUtil.getChannelImportance(context)); } if (notificationHubUtil.hasChannelShowBadge(context)) { builder.setShowBadge(notificationHubUtil.getChannelShowBadge(context)); } if (notificationHubUtil.hasChannelEnableLights(context)) { builder.enableLights(notificationHubUtil.getChannelEnableLights(context)); } if (notificationHubUtil.hasChannelEnableVibration(context)) { builder.enableVibration(notificationHubUtil.getChannelEnableVibration(context)); } notificationChannelID = NOTIFICATION_CHANNEL_ID; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = builder.build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE); if (notificationManager != null) { notificationManager.createNotificationChannel(channel); notificationChannelID = channel.getId(); } } } }