android.app.NotificationChannelGroup Java Examples

The following examples show how to use android.app.NotificationChannelGroup. 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: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 8 votes vote down vote up
public NotificationChannelGroup getNotificationChannelGroupWithChannels(String pkg,
        int uid, String groupId, boolean includeDeleted) {
    Preconditions.checkNotNull(pkg);
    Record r = getRecord(pkg, uid);
    if (r == null || groupId == null || !r.groups.containsKey(groupId)) {
        return null;
    }
    NotificationChannelGroup group = r.groups.get(groupId).clone();
    group.setChannels(new ArrayList<>());
    int N = r.channels.size();
    for (int i = 0; i < N; i++) {
        final NotificationChannel nc = r.channels.valueAt(i);
        if (includeDeleted || !nc.isDeleted()) {
            if (groupId.equals(nc.getGroup())) {
                group.addChannel(nc);
            }
        }
    }
    return group;
}
 
Example #2
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void writeXml(XmlSerializer out, boolean forBackup) throws IOException {
    out.startTag(null, TAG_RANKING);
    out.attribute(null, ATT_VERSION, Integer.toString(XML_VERSION));

    synchronized (mRecords) {
        final int N = mRecords.size();
        for (int i = 0; i < N; i++) {
            final Record r = mRecords.valueAt(i);
            //TODO: http://b/22388012
            if (forBackup && UserHandle.getUserId(r.uid) != UserHandle.USER_SYSTEM) {
                continue;
            }
            final boolean hasNonDefaultSettings =
                    r.importance != DEFAULT_IMPORTANCE
                        || r.priority != DEFAULT_PRIORITY
                        || r.visibility != DEFAULT_VISIBILITY
                        || r.showBadge != DEFAULT_SHOW_BADGE
                        || r.lockedAppFields != DEFAULT_LOCKED_APP_FIELDS
                        || r.channels.size() > 0
                        || r.groups.size() > 0;
            if (hasNonDefaultSettings) {
                out.startTag(null, TAG_PACKAGE);
                out.attribute(null, ATT_NAME, r.pkg);
                if (r.importance != DEFAULT_IMPORTANCE) {
                    out.attribute(null, ATT_IMPORTANCE, Integer.toString(r.importance));
                }
                if (r.priority != DEFAULT_PRIORITY) {
                    out.attribute(null, ATT_PRIORITY, Integer.toString(r.priority));
                }
                if (r.visibility != DEFAULT_VISIBILITY) {
                    out.attribute(null, ATT_VISIBILITY, Integer.toString(r.visibility));
                }
                out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge));
                out.attribute(null, ATT_APP_USER_LOCKED_FIELDS,
                        Integer.toString(r.lockedAppFields));

                if (!forBackup) {
                    out.attribute(null, ATT_UID, Integer.toString(r.uid));
                }

                for (NotificationChannelGroup group : r.groups.values()) {
                    group.writeXml(out);
                }

                for (NotificationChannel channel : r.channels.values()) {
                    if (forBackup) {
                        if (!channel.isDeleted()) {
                            channel.writeXmlForBackup(out, mContext);
                        }
                    } else {
                        channel.writeXml(out);
                    }
                }

                out.endTag(null, TAG_PACKAGE);
            }
        }
    }
    out.endTag(null, TAG_RANKING);
}
 
Example #3
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
        boolean fromTargetApp) {
    Preconditions.checkNotNull(pkg);
    Preconditions.checkNotNull(group);
    Preconditions.checkNotNull(group.getId());
    Preconditions.checkNotNull(!TextUtils.isEmpty(group.getName()));
    Record r = getOrCreateRecord(pkg, uid);
    if (r == null) {
        throw new IllegalArgumentException("Invalid package");
    }
    final NotificationChannelGroup oldGroup = r.groups.get(group.getId());
    if (!group.equals(oldGroup)) {
        // will log for new entries as well as name/description changes
        MetricsLogger.action(getChannelGroupLog(group.getId(), pkg));
    }
    if (oldGroup != null) {
        group.setChannels(oldGroup.getChannels());

        if (fromTargetApp) {
            group.setBlocked(oldGroup.isBlocked());
        }
    }
    r.groups.put(group.getId(), group);
}
 
Example #4
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
        int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) {
    Preconditions.checkNotNull(pkg);
    Map<String, NotificationChannelGroup> groups = new ArrayMap<>();
    Record r = getRecord(pkg, uid);
    if (r == null) {
        return ParceledListSlice.emptyList();
    }
    NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null);
    int N = r.channels.size();
    for (int i = 0; i < N; i++) {
        final NotificationChannel nc = r.channels.valueAt(i);
        if (includeDeleted || !nc.isDeleted()) {
            if (nc.getGroup() != null) {
                if (r.groups.get(nc.getGroup()) != null) {
                    NotificationChannelGroup ncg = groups.get(nc.getGroup());
                    if (ncg == null) {
                        ncg = r.groups.get(nc.getGroup()).clone();
                        ncg.setChannels(new ArrayList<>());
                        groups.put(nc.getGroup(), ncg);

                    }
                    ncg.addChannel(nc);
                }
            } else {
                nonGrouped.addChannel(nc);
            }
        }
    }
    if (includeNonGrouped && nonGrouped.getChannels().size() > 0) {
        groups.put(null, nonGrouped);
    }
    if (includeEmpty) {
        for (NotificationChannelGroup group : r.groups.values()) {
            if (!groups.containsKey(group.getId())) {
                groups.put(group.getId(), group);
            }
        }
    }
    return new ParceledListSlice<>(new ArrayList<>(groups.values()));
}
 
Example #5
Source File: LeanplumNotificationChannel.java    From Leanplum-Android-SDK with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
  }
}
 
Example #6
Source File: NotificationController.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
public static NotificationChannel registerChannelIfNeeded(Context context, String packageName) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        return null;
    }

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    String channelId = getChannelIdByPkg(packageName);
    NotificationChannel notificationChannel = manager.getNotificationChannel(channelId);

    if (notificationChannel != null) {
        if (ID_GROUP_APPLICATIONS.equals(notificationChannel.getGroup()) || TextUtils.isEmpty(notificationChannel.getGroup())) {
            manager.deleteNotificationChannel(channelId);
            notificationChannel = null;
        }
    }

    if (notificationChannel == null) {

        CharSequence name = ApplicationNameCache.getInstance().getAppName(context, packageName);
        if (name == null) {
            return null;
        }

        NotificationChannelGroup notificationChannelGroup = createGroupWithPackage(packageName, name);
        manager.createNotificationChannelGroup(notificationChannelGroup);

        notificationChannel = createChannelWithPackage(packageName, name);
        notificationChannel.setGroup(notificationChannelGroup.getId());

        manager.createNotificationChannel(notificationChannel);
    }

    return notificationChannel;

}
 
Example #7
Source File: NotificationChannelManagerHelper.java    From notification-channel-compat with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private static List<NotificationChannelGroupCompat> convertGroupListToCompat(List<NotificationChannelGroup> originals) {
    List<NotificationChannelGroupCompat> channels = new ArrayList<>(originals.size());
    for (NotificationChannelGroup origin : originals)
        channels.add(new NotificationChannelGroupCompat(origin));
    return channels;
}
 
Example #8
Source File: NotificationChannelManagerHelper.java    From notification-channel-compat with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private static List<NotificationChannelGroup> convertGroupCompatToList(List<NotificationChannelGroupCompat> originals) {
    List<NotificationChannelGroup> channels = new ArrayList<>(originals.size());
    for (NotificationChannelGroupCompat origin : originals)
        channels.add(origin.getOreoVersion());
    return channels;
}
 
Example #9
Source File: EntityAccount.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationChannelGroup group = new NotificationChannelGroup("group." + id, name);
    nm.createNotificationChannelGroup(group);

    NotificationChannel channel = new NotificationChannel(
            getNotificationChannelId(id), name,
            NotificationManager.IMPORTANCE_HIGH);
    channel.setGroup(group.getId());
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    channel.enableLights(true);
    nm.createNotificationChannel(channel);
}
 
Example #10
Source File: TupleFolderEx.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationChannelGroup group = new NotificationChannelGroup("group." + accountId, accountName);
    nm.createNotificationChannelGroup(group);

    NotificationChannel channel = new NotificationChannel(
            getNotificationChannelId(id), getDisplayName(context),
            NotificationManager.IMPORTANCE_HIGH);
    channel.setGroup(group.getId());
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    channel.enableLights(true);
    nm.createNotificationChannel(channel);
}
 
Example #11
Source File: LeanplumNotificationChannel.java    From Leanplum-Android-SDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: MyApplication.java    From GcmForMojo with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
private void notificationGroupInit(int group_id, int group_name) {
    // 通知渠道组的id.
    String group = getString(group_id);
    // 用户可见的通知渠道组名称.
    CharSequence name = getString(group_name);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(group, name));
}
 
Example #13
Source File: NotificationManager.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private static void createChannelGroup(Context ctx, String id, CharSequence name) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;
    NotificationChannelGroup group = new NotificationChannelGroup(id, name);
    android.app.NotificationManager mgr = (android.app.NotificationManager)
            ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    mgr.createNotificationChannelGroup(group);
}
 
Example #14
Source File: NotificationChannels.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(26)
private static void onCreate(@NonNull Context context, @NonNull NotificationManager notificationManager) {
  NotificationChannelGroup messagesGroup = new NotificationChannelGroup(CATEGORY_MESSAGES, context.getResources().getString(R.string.NotificationChannel_group_messages));
  notificationManager.createNotificationChannelGroup(messagesGroup);

  NotificationChannel messages     = new NotificationChannel(getMessagesChannel(context), context.getString(R.string.NotificationChannel_messages), NotificationManager.IMPORTANCE_HIGH);
  NotificationChannel calls        = new NotificationChannel(CALLS, context.getString(R.string.NotificationChannel_calls), NotificationManager.IMPORTANCE_HIGH);
  NotificationChannel failures     = new NotificationChannel(FAILURES, context.getString(R.string.NotificationChannel_failures), NotificationManager.IMPORTANCE_HIGH);
  NotificationChannel backups      = new NotificationChannel(BACKUPS, context.getString(R.string.NotificationChannel_backups), NotificationManager.IMPORTANCE_LOW);
  NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW);
  NotificationChannel other        = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW);

  messages.setGroup(CATEGORY_MESSAGES);
  messages.enableVibration(TextSecurePreferences.isNotificationVibrateEnabled(context));
  messages.setSound(TextSecurePreferences.getNotificationRingtone(context), getRingtoneAudioAttributes());
  setLedPreference(messages, TextSecurePreferences.getNotificationLedColor(context));

  calls.setShowBadge(false);
  backups.setShowBadge(false);
  lockedStatus.setShowBadge(false);
  other.setShowBadge(false);

  notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other));

  if (BuildConfig.AUTOMATIC_UPDATES) {
    NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.NotificationChannel_app_updates), NotificationManager.IMPORTANCE_HIGH);
    notificationManager.createNotificationChannel(appUpdates);
  } else {
    notificationManager.deleteNotificationChannel(APP_UPDATES);
  }
}
 
Example #15
Source File: NotificationChannels.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@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());
    }

}
 
Example #16
Source File: NotificationChannels.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@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());
    }

}
 
Example #17
Source File: NotificationCenter.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private String getNotificationChannelGroup(NotificationManagerCompat notificationManager) {
    if (notificationChannelsSupported() && notificationManager.getNotificationChannelGroup(CH_GRP_MSG) == null) {
        NotificationChannelGroup chGrp = new NotificationChannelGroup(CH_GRP_MSG, context.getString(R.string.pref_chats));
        notificationManager.createNotificationChannelGroup(chGrp);
    }
    return CH_GRP_MSG;
}
 
Example #18
Source File: NotifyManager.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private void createNotifyChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (mNotificationManager != null) {
            mNotificationManager.createNotificationChannelGroup(
                new NotificationChannelGroup(mGroupId, mGroupName));
            NotificationChannel channelMsg =
                new NotificationChannel(mChannelMsgId, mChannelMsgName,
                    NotificationManager.IMPORTANCE_DEFAULT);
            channelMsg.setDescription(mChannelMsgDes);
            channelMsg.enableLights(true);
            channelMsg.setLightColor(Color.BLUE);
            channelMsg.enableVibration(false);
            channelMsg.setVibrationPattern(new long[] { 100, 200, 300, 400 });
            channelMsg.setShowBadge(true);
            channelMsg.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
            channelMsg.setGroup(mGroupId);
            mNotificationManager.createNotificationChannel(channelMsg);

            NotificationChannel channelService =
                new NotificationChannel(mChannelServiceId, mChannelServiceName,
                    NotificationManager.IMPORTANCE_LOW);
            channelService.setDescription(mChannelServiceDes);
            channelService.enableLights(false);
            channelService.enableVibration(false);
            channelService.setShowBadge(false);
            channelService.setSound(null, null);
            channelService.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            channelService.setGroup(mGroupId);
            mNotificationManager.createNotificationChannel(channelService);
        }
    }
}
 
Example #19
Source File: NotificationListenerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onNotificationChannelGroupModification(String pkgName, UserHandle user,
        NotificationChannelGroup group,
        @ChannelOrGroupModificationTypes int modificationType) {
    SomeArgs args = SomeArgs.obtain();
    args.arg1 = pkgName;
    args.arg2 = user;
    args.arg3 = group;
    args.arg4 = modificationType;
    mHandler.obtainMessage(
            MyHandler.MSG_ON_NOTIFICATION_CHANNEL_GROUP_MODIFIED, args).sendToTarget();
}
 
Example #20
Source File: NotificationListenerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all notification channel groups belonging to the given package for a given user.
 *
 * <p>This method will throw a security exception if you don't have access to notifications
 * for the given user.</p>
 * <p>The caller must have {@link CompanionDeviceManager#getAssociations() an associated
 * device} in order to use this method.
 *
 * @param pkg The package to retrieve channel groups for.
 */
public final List<NotificationChannelGroup> getNotificationChannelGroups(@NonNull String pkg,
        @NonNull UserHandle user) {
    if (!isBound()) return null;
    try {

        return getNotificationInterface().getNotificationChannelGroupsFromPrivilegedListener(
                mWrapper, pkg, user).getList();
    } catch (RemoteException e) {
        Log.v(TAG, "Unable to contact notification manager", e);
        throw e.rethrowFromSystemServer();
    }
}
 
Example #21
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isGroupBlocked(String packageName, int uid, String groupId) {
    if (groupId == null) {
        return false;
    }
    Record r = getOrCreateRecord(packageName, uid);
    NotificationChannelGroup group = r.groups.get(groupId);
    if (group == null) {
        return false;
    }
    return group.isBlocked();
}
 
Example #22
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public NotificationChannelGroup getNotificationChannelGroup(String groupId, String pkg,
        int uid) {
    Preconditions.checkNotNull(pkg);
    Record r = getRecord(pkg, uid);
    if (r == null) {
        return null;
    }
    return r.groups.get(groupId);
}
 
Example #23
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
        int uid) {
    Record r = getRecord(pkg, uid);
    if (r == null) {
        return new ArrayList<>();
    }
    return r.groups.values();
}
 
Example #24
Source File: RankingHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void dumpRecords(ProtoOutputStream proto, long fieldId,
        @NonNull NotificationManagerService.DumpFilter filter,
        ArrayMap<String, Record> records) {
    final int N = records.size();
    long fToken;
    for (int i = 0; i < N; i++) {
        final Record r = records.valueAt(i);
        if (filter.matches(r.pkg)) {
            fToken = proto.start(fieldId);

            proto.write(RecordProto.PACKAGE, r.pkg);
            proto.write(RecordProto.UID, r.uid);
            proto.write(RecordProto.IMPORTANCE, r.importance);
            proto.write(RecordProto.PRIORITY, r.priority);
            proto.write(RecordProto.VISIBILITY, r.visibility);
            proto.write(RecordProto.SHOW_BADGE, r.showBadge);

            for (NotificationChannel channel : r.channels.values()) {
                channel.writeToProto(proto, RecordProto.CHANNELS);
            }
            for (NotificationChannelGroup group : r.groups.values()) {
                group.writeToProto(proto, RecordProto.CHANNEL_GROUPS);
            }

            proto.end(fToken);
        }
    }
}
 
Example #25
Source File: NotificationService.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.O)
void initializeChannels() {
    final Context c = mXmppConnectionService;
    final NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("status", c.getString(R.string.notification_group_status_information)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("chats", c.getString(R.string.notification_group_messages)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("calls", c.getString(R.string.notification_group_calls)));
    final NotificationChannel foregroundServiceChannel = new NotificationChannel(FOREGROUND_CHANNEL_ID,
            c.getString(R.string.foreground_service_channel_name),
            NotificationManager.IMPORTANCE_MIN);
    foregroundServiceChannel.setDescription(c.getString(R.string.foreground_service_channel_description));
    foregroundServiceChannel.setShowBadge(false);
    foregroundServiceChannel.setGroup("status");
    notificationManager.createNotificationChannel(foregroundServiceChannel);

    final NotificationChannel backupChannel = new NotificationChannel(BACKUP_CHANNEL_ID,
            c.getString(R.string.backup_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    backupChannel.setShowBadge(false);
    backupChannel.setGroup("status");
    notificationManager.createNotificationChannel(backupChannel);

    final NotificationChannel videoCompressionChannel = new NotificationChannel(VIDEOCOMPRESSION_CHANNEL_ID,
            c.getString(R.string.video_compression_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    videoCompressionChannel.setShowBadge(false);
    videoCompressionChannel.setGroup("status");
    notificationManager.createNotificationChannel(videoCompressionChannel);

    final NotificationChannel AppUpdateChannel = new NotificationChannel(UPDATE_CHANNEL_ID,
            c.getString(R.string.app_update_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    AppUpdateChannel.setShowBadge(false);
    AppUpdateChannel.setGroup("status");
    notificationManager.createNotificationChannel(AppUpdateChannel);

    final NotificationChannel incomingCallsChannel = new NotificationChannel("incoming_calls",
            c.getString(R.string.incoming_calls_channel_name),
            NotificationManager.IMPORTANCE_HIGH);
    incomingCallsChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
            .build());
    incomingCallsChannel.setShowBadge(false);
    incomingCallsChannel.setLightColor(LED_COLOR);
    incomingCallsChannel.enableLights(true);
    incomingCallsChannel.setGroup("calls");
    incomingCallsChannel.setBypassDnd(true);
    incomingCallsChannel.enableVibration(true);
    incomingCallsChannel.setVibrationPattern(CALL_PATTERN);
    notificationManager.createNotificationChannel(incomingCallsChannel);

    final NotificationChannel ongoingCallsChannel = new NotificationChannel("ongoing_calls",
            c.getString(R.string.ongoing_calls_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    ongoingCallsChannel.setShowBadge(false);
    ongoingCallsChannel.setGroup("calls");
    notificationManager.createNotificationChannel(ongoingCallsChannel);


    final NotificationChannel messagesChannel = new NotificationChannel("messages",
            c.getString(R.string.messages_channel_name),
            NotificationManager.IMPORTANCE_HIGH);
    messagesChannel.setShowBadge(true);
    messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
            .build());
    messagesChannel.setLightColor(LED_COLOR);
    final int dat = 70;
    final long[] pattern = {0, 3 * dat, dat, dat};
    messagesChannel.setVibrationPattern(pattern);
    messagesChannel.enableVibration(true);
    messagesChannel.enableLights(true);
    messagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(messagesChannel);

    final NotificationChannel silentMessagesChannel = new NotificationChannel("silent_messages",
            c.getString(R.string.silent_messages_channel_name),
            NotificationManager.IMPORTANCE_LOW);
    silentMessagesChannel.setDescription(c.getString(R.string.silent_messages_channel_description));
    silentMessagesChannel.setShowBadge(true);
    silentMessagesChannel.setLightColor(LED_COLOR);
    silentMessagesChannel.enableLights(true);
    silentMessagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(silentMessagesChannel);

    final NotificationChannel quietHoursChannel = new NotificationChannel("quiet_hours",
            c.getString(R.string.title_pref_quiet_hours),
            NotificationManager.IMPORTANCE_LOW);
    quietHoursChannel.setShowBadge(true);
    quietHoursChannel.setLightColor(LED_COLOR);
    quietHoursChannel.enableLights(true);
    quietHoursChannel.setGroup("chats");
    quietHoursChannel.enableVibration(false);
    quietHoursChannel.setSound(null, null);
    notificationManager.createNotificationChannel(quietHoursChannel);
}
 
Example #26
Source File: NotificationChannels.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@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 #27
Source File: NotificationChannels.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@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 #28
Source File: NotificationChannels.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@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 #29
Source File: NotificationChannels.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@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 #30
Source File: NotificationController.java    From MiPushFramework with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(26)
private static NotificationChannelGroup createGroupWithPackage(@NonNull String packageName,
                                                               @NonNull CharSequence name) {
    return new NotificationChannelGroup(getGroupIdByPkg(packageName), name);
}