项目:Leanplum-Android-SDK
文件:LeanplumNotificationChannel.java
/**
* Create push notification channel group.
*
* @param context The application context.
* @param groupId The id of the group.
* @param groupName The user-visible name of the group.
*/
private static void createNotificationGroup(Context context,String groupId,String groupName) {
if (context == null || TextUtils.isEmpty(groupId)) {
return;
}
if (BuildUtil.isNotificationChannelSupported(context)) {
try {
notificationmanager notificationmanager =
(notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationmanager == null) {
Log.e("Notification manager is null");
return;
}
notificationmanager.createNotificationChannelGroup(new NotificationChannelGroup(groupId,groupName));
} catch (Throwable t) {
Util.handleException(t);
}
}
}
项目:rview
文件:NotificationsHelper.java
@TargetApi(Build.VERSION_CODES.O)
public static void createNotificationChannel(Context context,Account account) {
if (AndroidHelper.isApi26OrGreater()) {
final String defaultChannelName = context.getString(
R.string.notifications_default_channel_name,account.getRepositorydisplayName(),account.getAccountdisplayName());
final notificationmanager nm =
(notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.createNotificationChannelGroup(new NotificationChannelGroup(
account.getAccountHash(),defaultChannelName));
NotificationChannel channel = new NotificationChannel(account.getAccountHash(),defaultChannelName,notificationmanager.IMPORTANCE_DEFAULT);
channel.setDescription(context.getString(R.string.notifications_default_channel_description));
channel.enableVibration(true);
channel.enableLights(true);
channel.setLightColor(ContextCompat.getColor(context,R.color.primaryDark));
channel.setShowBadge(true);
channel.setGroup(account.getAccountHash());
nm.createNotificationChannel(channel);
}
}
项目:dns66
文件:NotificationChannels.java
public static void onCreate(Context context) {
notificationmanager notificationmanager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
return;
notificationmanager.createNotificationChannelGroup(new NotificationChannelGroup(GROUP_SERVICE,context.getString(R.string.notifications_group_service)));
notificationmanager.createNotificationChannelGroup(new NotificationChannelGroup(GROUP_UPDATE,context.getString(R.string.notifications_group_updates)));
NotificationChannel runningChannel = new NotificationChannel(SERVICE_RUNNING,context.getString(R.string.notifications_running),notificationmanager.IMPORTANCE_MIN);
runningChannel.setDescription(context.getString(R.string.notifications_running_desc));
runningChannel.setGroup(GROUP_SERVICE);
runningChannel.setShowBadge(false);
notificationmanager.createNotificationChannel(runningChannel);
NotificationChannel pausedChannel = new NotificationChannel(SERVICE_PAUSED,context.getString(R.string.notifications_paused),notificationmanager.IMPORTANCE_LOW);
pausedChannel.setDescription(context.getString(R.string.notifications_paused_desc));
pausedChannel.setGroup(GROUP_SERVICE);
pausedChannel.setShowBadge(false);
notificationmanager.createNotificationChannel(pausedChannel);
NotificationChannel updateChannel = new NotificationChannel(UPDATE_STATUS,context.getString(R.string.notifications_update),notificationmanager.IMPORTANCE_LOW);
updateChannel.setDescription(context.getString(R.string.notifications_update_desc));
updateChannel.setGroup(GROUP_UPDATE);
updateChannel.setShowBadge(false);
notificationmanager.createNotificationChannel(updateChannel);
}
项目:Leanplum-Android-SDK
文件:LeanplumNotificationChannel.java
/**
* Get list of Notification groups.
*
* @param context The application context.
* @return Returns all notification groups.
*/
static List<NotificationChannelGroup> getNotificationGroups(Context context) {
if (BuildUtil.isNotificationChannelSupported(context)) {
notificationmanager notificationmanager = (notificationmanager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
if (notificationmanager == null) {
Log.e("Cannot get Notification Channel Groups,notificationmanager is null.");
return null;
}
return notificationmanager.getNotificationChannelGroups();
}
return null;
}
项目:xDrip
文件:NotificationChannels.java
@TargetApi(26)
public static void cleanAllNotificationChannels() {
// Todo this isn't right yet
List<NotificationChannel> channels = getNotifManager().getNotificationChannels();
for (NotificationChannel channel : channels) {
getNotifManager().deleteNotificationChannel(channel.getId());
}
List<NotificationChannelGroup> groups = getNotifManager().getNotificationChannelGroups();
for (NotificationChannelGroup group : groups) {
getNotifManager().deleteNotificationChannel(group.getId());
}
}
项目:xDrip-plus
文件:NotificationChannels.java
@TargetApi(26)
public static void cleanAllNotificationChannels() {
// Todo this isn't right yet
List<NotificationChannel> channels = getNotifManager().getNotificationChannels();
for (NotificationChannel channel : channels) {
getNotifManager().deleteNotificationChannel(channel.getId());
}
List<NotificationChannelGroup> groups = getNotifManager().getNotificationChannelGroups();
for (NotificationChannelGroup group : groups) {
getNotifManager().deleteNotificationChannel(group.getId());
}
}
项目:Android-O-Feature
文件:NotificationChannelActivity.java
private void setupNotificationChannel(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannelGroup timelineGroup = new NotificationChannelGroup(
NotificationKey.CHANNEL_GROUP_TIMELINE,NotificationKey.CHANNEL_NAME_TIMELINE);
NotificationChannelGroup friendGroup = new NotificationChannelGroup(
NotificationKey.CHANNEL_GROUP_FRIEND,NotificationKey.CHANNEL_NAME_FRIEND);
NotificationChannel friendConfirmationsChannel = new NotificationChannel(
NotificationKey.CHANNEL_ID_FRIEND_CONFIRMATIONS,NotificationKey.CHANNEL_NAME_FRIEND_CONFIRMATIONS,notificationmanager.IMPORTANCE_DEFAULT);
friendConfirmationsChannel.setGroup(NotificationKey.CHANNEL_GROUP_FRIEND);
NotificationChannel friendRequestsChannel = new NotificationChannel(
NotificationKey.CHANNEL_ID_FRIEND_REQUESTS,NotificationKey.CHANNEL_NAME_FRIEND_REQUESTS,notificationmanager.IMPORTANCE_DEFAULT);
friendRequestsChannel.setGroup(NotificationKey.CHANNEL_GROUP_FRIEND);
NotificationChannel photoTagsChannel = new NotificationChannel(
NotificationKey.CHANNEL_ID_PHOTO_TAGS,NotificationKey.CHANNEL_NAME_PHOTO_TAGS,notificationmanager.IMPORTANCE_DEFAULT);
photoTagsChannel.setGroup(NotificationKey.CHANNEL_GROUP_FRIEND);
NotificationChannel commentChannel = new NotificationChannel(
NotificationKey.CHANNEL_ID_COMMENT,NotificationKey.CHANNEL_NAME_COMMENT,notificationmanager.IMPORTANCE_DEFAULT);
commentChannel.setGroup(NotificationKey.CHANNEL_GROUP_TIMELINE);
NotificationChannel logInAlertChannel = new NotificationChannel(
NotificationKey.CHANNEL_ID_LOG_IN_ALERT,NotificationKey.CHANNEL_NAME_LOG_IN_ALERT,notificationmanager.IMPORTANCE_DEFAULT);
notificationmanager manager = (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannelGroup(timelineGroup);
manager.createNotificationChannelGroup(friendGroup);
manager.createNotificationChannel(friendConfirmationsChannel);
manager.createNotificationChannel(friendRequestsChannel);
manager.createNotificationChannel(photoTagsChannel);
manager.createNotificationChannel(commentChannel);
manager.createNotificationChannel(logInAlertChannel);
}
}
项目:xDrip
文件:NotificationChannels.java
@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);
channel.setGroup(template.getGroup());
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;
}
项目:xDrip-plus
文件:NotificationChannels.java
@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(channel.getGroup())));
// create this channel if it doesn't exist or update text
getNotifManager().createNotificationChannel(channel);
return channel;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。