本文整理汇总了Java中android.app.NotificationChannel.setGroup方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationChannel.setGroup方法的具体用法?Java NotificationChannel.setGroup怎么用?Java NotificationChannel.setGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.NotificationChannel
的用法示例。
在下文中一共展示了NotificationChannel.setGroup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNotificationChannel
import android.app.NotificationChannel; //导入方法依赖的package包/类
@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);
}
}
示例2: onCreate
import android.app.NotificationChannel; //导入方法依赖的package包/类
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);
}
示例3: createNotificationChannel
import android.app.NotificationChannel; //导入方法依赖的package包/类
/**
* Create push notification channel with provided id, name and importance of the channel.
* You can call this method also when you need to update the name or description of a channel, at
* this case you should use original channel id.
*
* @param context The application context.
* @param channelId The id of the channel.
* @param channelName The user-visible name of the channel.
* @param channelImportance The importance of the channel. Use value from 0 to 5. 3 is default.
* Read more https://developer.android.com/reference/android/app/NotificationManager.html#IMPORTANCE_DEFAULT
* Once you create a notification channel, only the system can modify its importance.
* @param channelDescription The user-visible description of the channel.
* @param groupId The id of push notification channel group.
* @param enableLights True if lights enable for this channel.
* @param lightColor Light color for notifications posted to this channel, if the device supports
* this feature.
* @param enableVibration True if vibration enable for this channel.
* @param vibrationPattern Vibration pattern for notifications posted to this channel.
* @param lockscreenVisibility How to be shown on the lockscreen.
* @param bypassDnd Whether should notification bypass DND.
* @param showBadge Whether should notification show badge.
*/
private static void createNotificationChannel(Context context, String channelId, String
channelName, int channelImportance, String channelDescription, String groupId, boolean
enableLights, int lightColor, boolean enableVibration, long[] vibrationPattern, int
lockscreenVisibility, boolean bypassDnd, boolean showBadge) {
if (context == null || TextUtils.isEmpty(channelId)) {
return;
}
if (BuildUtil.isNotificationChannelSupported(context)) {
try {
NotificationManager notificationManager =
context.getSystemService(NotificationManager.class);
if (notificationManager == null) {
Log.e("Notification manager is null");
return;
}
NotificationChannel notificationChannel = new NotificationChannel(channelId,
channelName, channelImportance);
if (!TextUtils.isEmpty(channelDescription)) {
notificationChannel.setDescription(channelDescription);
}
if (enableLights) {
notificationChannel.enableLights(true);
notificationChannel.setLightColor(lightColor);
}
if (enableVibration) {
notificationChannel.enableVibration(true);
// Workaround for https://issuetracker.google.com/issues/63427588
if (vibrationPattern != null && vibrationPattern.length != 0) {
notificationChannel.setVibrationPattern(vibrationPattern);
}
}
if (!TextUtils.isEmpty(groupId)) {
notificationChannel.setGroup(groupId);
}
notificationChannel.setLockscreenVisibility(lockscreenVisibility);
notificationChannel.setBypassDnd(bypassDnd);
notificationChannel.setShowBadge(showBadge);
notificationManager.createNotificationChannel(notificationChannel);
} catch (Throwable t) {
Util.handleException(t);
}
}
}
示例4: setupNotificationChannel
import android.app.NotificationChannel; //导入方法依赖的package包/类
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);
}
}
示例5: getChan
import android.app.NotificationChannel; //导入方法依赖的package包/类
@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;
}