android.app.NotificationManager#IMPORTANCE_HIGH源码实例Demo

下面列出了android.app.NotificationManager#IMPORTANCE_HIGH 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void testNotification() {
    NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel("111", "CN111", NotificationManager.IMPORTANCE_HIGH);
        mNotificationManager.createNotificationChannel(channel);
        mBuilder = new NotificationCompat.Builder(this, "111");
    } else {
        mBuilder = new NotificationCompat.Builder(this);
    }

    mBuilder.setSmallIcon(R.drawable.ic_launcher);
    mBuilder.setContentTitle("插件框架Title").setContentText("插件框架Content")
            .setTicker("插件框架Ticker");
    Notification mNotification = mBuilder.build();
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;
    //mBuilder.setContentIntent()
    LogUtil.e("NotificationManager.notify");
    mNotificationManager.notify(456, mNotification);
}
 
private void initDefaultChannels() {
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        return;
    }

    CharSequence channelName = SoftwareInformation.getAppName(context);

    NotificationChannel notificationChannel = new NotificationChannel(MM_DEFAULT_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT);
    notificationChannel.enableLights(true);
    notificationChannel.enableVibration(true);
    notificationManager.createNotificationChannel(notificationChannel);

    NotificationSettings notificationSettings = getNotificationSettings();
    if (notificationSettings != null && notificationSettings.areHeadsUpNotificationsEnabled()) {
        NotificationChannel highPriorityNotificationChannel = new NotificationChannel(MM_DEFAULT_HIGH_PRIORITY_CHANNEL_ID, channelName + " High Priority", NotificationManager.IMPORTANCE_HIGH);
        highPriorityNotificationChannel.enableLights(true);
        highPriorityNotificationChannel.enableVibration(true);
        notificationManager.createNotificationChannel(highPriorityNotificationChannel);
    }
}
 
源代码3 项目: AndroidGodEye   文件: Notifier.java
public static Notification create(Context context, Config config) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    Notification.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel =
                Objects.requireNonNull(notificationManager).getNotificationChannel("AndroidGodEye");
        if (notificationChannel == null) {
            NotificationChannel channel = new NotificationChannel("AndroidGodEye", "AndroidGodEye", NotificationManager.IMPORTANCE_HIGH);
            channel.setDescription("AndroidGodEye");
            notificationManager.createNotificationChannel(channel);
        }
        builder = new Notification.Builder(context, "AndroidGodEye");
    } else {
        builder = new Notification.Builder(context);
    }
    return builder.setSmallIcon(R.drawable.androidgodeye_ic_remove_red_eye)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.androidgodeye_ic_launcher))
            .setContentTitle(config.getTitle())
            .setContentText(config.getMessage())
            .setStyle(new Notification.BigTextStyle().bigText(config.getMessage()))
            .build();
}
 
private void createNotificationChannel() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = getString(R.string.earthquake_channel_name);
    NotificationChannel channel = new NotificationChannel(
      NOTIFICATION_CHANNEL,
      name,
      NotificationManager.IMPORTANCE_HIGH);
    channel.enableVibration(true);
    channel.enableLights(true);
    NotificationManager notificationManager =
      getSystemService(NotificationManager.class);
    notificationManager.createNotificationChannel(channel);
  }
}
 
private void createNotificationChannel() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = getString(R.string.earthquake_channel_name);
    NotificationChannel channel = new NotificationChannel(
      NOTIFICATION_CHANNEL,
      name,
      NotificationManager.IMPORTANCE_HIGH);
    channel.enableVibration(true);
    channel.enableLights(true);
    NotificationManager notificationManager =
      getSystemService(NotificationManager.class);
    notificationManager.createNotificationChannel(channel);
  }
}
 
源代码6 项目: Wrox-ProfessionalAndroid-4E   文件: MyActivity.java
public void createMessagesNotificationChannel(Context context) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = context.getString(R.string.messages_channel_name);
    NotificationChannel channel = new NotificationChannel(
      MESSAGES_CHANNEL,
      name,
      NotificationManager.IMPORTANCE_HIGH);

    NotificationManager notificationManager =
      context.getSystemService(NotificationManager.class);

    notificationManager.createNotificationChannel(channel);
  }
}
 
@Override
public void onCreate() {
    super.onCreate();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(mNotificationId, mNotificationName, NotificationManager.IMPORTANCE_HIGH);
        mNotificationManager.createNotificationChannel(channel);
    }
    startForeground(1, getNotification());
}
 
源代码8 项目: FairEmail   文件: EntityAccount.java
@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);
}
 
源代码9 项目: revolution-irc   文件: WarningHelper.java
public static String getNotificationChannel(Context context) {
    if (!sNotificationChannelCreated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_NAME,
                context.getString(R.string.notification_channel_warning),
                NotificationManager.IMPORTANCE_HIGH);
        channel.setGroup(
                io.mrarm.irc.NotificationManager.getSystemNotificationChannelGroup(context));
        notificationManager.createNotificationChannel(channel);
        sNotificationChannelCreated = true;
    }
    return NOTIFICATION_CHANNEL_NAME;
}
 
源代码10 项目: fresco   文件: ImagePipelineNotificationFragment.java
private void createNotificationChannel() {
  NotificationManager mNotificationManager =
      (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
  CharSequence name = getString(R.string.imagepipeline_notification_channel_name);

  int importance =
      NotificationManager
          .IMPORTANCE_HIGH; // high importance shows the notification on the user screen.

  NotificationChannel mChannel =
      new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
  mNotificationManager.createNotificationChannel(mChannel);
}
 
private void createNotificationChannel() {
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mChannelID = getPackageName() + ".channel_01";

    // The user-visible name of the channel.
    CharSequence name = getString(R.string.channel_name);

    // The user-visible description of the channel
    String description = getString(R.string.channel_description);
    int importance = NotificationManager.IMPORTANCE_HIGH;
    NotificationChannel mChannel = new NotificationChannel(mChannelID, name, importance);

    // Configure the notification channel.
    mChannel.setDescription(description);
    mChannel.enableLights(true);

    // Sets the notification light color for notifications posted to this
    // channel, if the device supports this feature.
    mChannel.setLightColor(Color.RED);
    mChannel.enableVibration(true);
    mChannel.setVibrationPattern(mVibratePattern);

    Uri mSoundURI = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.alarm_rooster);
    mChannel.setSound(mSoundURI, (new AudioAttributes.Builder())
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build());

    mNotificationManager.createNotificationChannel(mChannel);
}
 
@RequiresApi(api = Build.VERSION_CODES.O)
private synchronized void createAppNotificationChannel() throws ApplozicException {
    CharSequence name = MobiComKitConstants.APP_NOTIFICATION_NAME;
    int importance = NotificationManager.IMPORTANCE_HIGH;

    if (mNotificationManager != null && mNotificationManager.getNotificationChannel(MobiComKitConstants.AL_APP_NOTIFICATION) == null) {
        NotificationChannel mChannel = new NotificationChannel(MobiComKitConstants.AL_APP_NOTIFICATION, name, importance);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.GREEN);
        mChannel.setShowBadge(ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled());

        if (ApplozicClient.getInstance(context).getVibrationOnNotification()) {
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        }

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION).build();

        if (TextUtils.isEmpty(soundFilePath)) {
            throw new ApplozicException("Custom sound path is required to create App notification channel. " +
                    "Please set a sound path using Applozic.getInstance(context).setCustomNotificationSound(your-sound-file-path)");
        }
        mChannel.setSound(Uri.parse(soundFilePath), audioAttributes);
        mNotificationManager.createNotificationChannel(mChannel);
        Utils.printLog(context, TAG, "Created app notification channel");
    }
}
 
源代码13 项目: restcomm-android-sdk   文件: RCDevice.java
/**
 * Method returns the Notification builder
 * For Oreo devices we can have channels with HIGH and LOW importance.
 * If highImportance is true builder will be created with HIGH priority
 * For pre Oreo devices builder without channel will be returned
 * @param highImportance true if we need HIGH channel, false if we need LOW
 * @return
 */
private NotificationCompat.Builder getNotificationBuilder(boolean highImportance){
   NotificationCompat.Builder builder;
   if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
      if (highImportance){
         NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL_ID, PRIMARY_CHANNEL, NotificationManager.IMPORTANCE_HIGH);
         channel.setLightColor(Color.GREEN);
         channel.enableLights(true);
         channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
         channel.enableVibration(true);
         channel.setVibrationPattern(notificationVibrationPattern);

         ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
         builder = new NotificationCompat.Builder(RCDevice.this, PRIMARY_CHANNEL_ID);
      } else {
         NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
         NotificationChannel notificationChannel = new NotificationChannel(DEFAULT_FOREGROUND_CHANNEL_ID, DEFAULT_FOREGROUND_CHANNEL, NotificationManager.IMPORTANCE_LOW);
         notificationManager.createNotificationChannel(notificationChannel);

        builder = new NotificationCompat.Builder(RCDevice.this, DEFAULT_FOREGROUND_CHANNEL_ID);
      }

   } else {
      builder = new NotificationCompat.Builder(RCDevice.this);
   }

   return builder;
}
 
/**
 * Create and show a direct notification containing the received FCM message.
 *
 * @param sender         the id of the message's sender
 * @param senderFullName the display name of the message's sender
 * @param text           the message text
 */
private void sendDirectNotification(String sender, String senderFullName, String text, String channel) {

    Intent intent = new Intent(this, MessageListActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(ChatUI.BUNDLE_RECIPIENT, new ChatUser(sender, senderFullName));
    intent.putExtra(BUNDLE_CHANNEL_TYPE, channel);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this, channel)
                    .setSmallIcon(R.drawable.ic_notification_small)
                    .setContentTitle(senderFullName)
                    .setContentText(text)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // Oreo fix
    String channelId = channel;
    String channelName = channel;
    int importance = NotificationManager.IMPORTANCE_HIGH;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel mChannel = new NotificationChannel(
                channelId, channelName, importance);
        notificationManager.createNotificationChannel(mChannel);
    }

    int notificationId = (int) new Date().getTime();
    notificationManager.notify(notificationId, notificationBuilder.build());
}
 
源代码15 项目: android   文件: NotificationSupport.java
@RequiresApi(Build.VERSION_CODES.O)
public static void createChannels(NotificationManager notificationManager) {
    try {
        // Low importance so that persistent notification can be sorted towards bottom of
        // notification shade. Also prevents vibrations caused by persistent notification
        NotificationChannel foreground =
                new NotificationChannel(
                        Channel.FOREGROUND,
                        "Gotify foreground notification",
                        NotificationManager.IMPORTANCE_LOW);
        foreground.setShowBadge(false);

        NotificationChannel messagesImportanceMin =
                new NotificationChannel(
                        Channel.MESSAGES_IMPORTANCE_MIN,
                        "Min priority messages (<1)",
                        NotificationManager.IMPORTANCE_MIN);

        NotificationChannel messagesImportanceLow =
                new NotificationChannel(
                        Channel.MESSAGES_IMPORTANCE_LOW,
                        "Low priority messages (1-3)",
                        NotificationManager.IMPORTANCE_LOW);

        NotificationChannel messagesImportanceDefault =
                new NotificationChannel(
                        Channel.MESSAGES_IMPORTANCE_DEFAULT,
                        "Normal priority messages (4-7)",
                        NotificationManager.IMPORTANCE_DEFAULT);
        messagesImportanceDefault.enableLights(true);
        messagesImportanceDefault.setLightColor(Color.CYAN);
        messagesImportanceDefault.enableVibration(true);

        NotificationChannel messagesImportanceHigh =
                new NotificationChannel(
                        Channel.MESSAGES_IMPORTANCE_HIGH,
                        "High priority messages (>7)",
                        NotificationManager.IMPORTANCE_HIGH);
        messagesImportanceHigh.enableLights(true);
        messagesImportanceHigh.setLightColor(Color.CYAN);
        messagesImportanceHigh.enableVibration(true);

        notificationManager.createNotificationChannel(foreground);
        notificationManager.createNotificationChannel(messagesImportanceMin);
        notificationManager.createNotificationChannel(messagesImportanceLow);
        notificationManager.createNotificationChannel(messagesImportanceDefault);
        notificationManager.createNotificationChannel(messagesImportanceHigh);
    } catch (Exception e) {
        Log.e("Could not create channel", e);
    }
}
 
源代码16 项目: PermissionEverywhere   文件: NotificationHelper.java
public static void sendNotification(Context context,
                                    String[] permissions,
                                    int requestCode,
                                    String notificationTitle,
                                    String notificationText,
                                    int notificationIcon,
                                    ResultReceiver receiver) {

    Intent intent = new Intent(context, PermissionActivity.class);
    intent.putExtra(Const.REQUEST_CODE, requestCode);
    intent.putExtra(Const.PERMISSIONS_ARRAY, permissions);
    intent.putExtra(Const.RESULT_RECEIVER, receiver);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE_PUSH, intent,
            PendingIntent.FLAG_ONE_SHOT);

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_name), NotificationManager.IMPORTANCE_HIGH);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setShowBadge(true);
        notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        notificationManager.createNotificationChannel(notificationChannel);
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
            .setSmallIcon(notificationIcon)
            .setContentTitle(notificationTitle)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText))
            .setContentText(notificationText)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setVibrate(new long[0])
            .setContentIntent(pendingIntent);

    notificationManager.notify(requestCode, notificationBuilder.build());
}
 
源代码17 项目: react-native-fcm   文件: FIRMessagingModule.java
@ReactMethod
public void createNotificationChannel(ReadableMap details, Promise promise){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager mngr = (NotificationManager) getReactApplicationContext().getSystemService(NOTIFICATION_SERVICE);
        String id = details.getString("id");
        String name = details.getString("name");
        String priority = details.getString("priority");
        int importance;
        switch(priority) {
            case "min":
                importance = NotificationManager.IMPORTANCE_MIN;
                break;
            case "low":
                importance = NotificationManager.IMPORTANCE_LOW;
                break;
            case "high":
                importance = NotificationManager.IMPORTANCE_HIGH;
                break;
            case "max":
                importance = NotificationManager.IMPORTANCE_MAX;
                break;
            default:
                importance = NotificationManager.IMPORTANCE_DEFAULT;
        }
        if (mngr.getNotificationChannel(id) != null) {
            promise.resolve(null);
            return;
        }
        //
        NotificationChannel channel = new NotificationChannel(
                id,
                name,
                importance);
        // Configure the notification channel.
        if(details.hasKey("description")){
            channel.setDescription(details.getString("description"));
        }
        mngr.createNotificationChannel(channel);
    }
    promise.resolve(null);
}
 
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

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

    if (manager == null) {
        Log.d(LOG_TAG, "Notification manager not found");
        return;
    }

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_launcher);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

        channel.enableVibration(true);
        channel.setVibrationPattern(new long[] {100, 200, 100, 200});

        builder.setChannelId(NOTIFICATION_CHANNEL_ID);
        manager.createNotificationChannel(channel);

    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.setPriority(Notification.PRIORITY_HIGH);
    }

    PushData pushData = PushData.getChatNotification(remoteMessage.getData());

    switch(pushData.getType()) {
        case END:
            builder.setContentTitle("Chat ended");
            builder.setContentText("The chat has ended!");
            break;
        case MESSAGE:
            builder.setContentTitle("Chat message");
            builder.setContentText("New chat message!");
            break;
        case NOT_CHAT:
            // ignore
            break;
    }

    manager.notify(NOTIFICATION_ID, builder.build());

    // IMPORTANT! forward the notification data to the SDK
    ZopimChatApi.onMessageReceived(pushData);
}
 
源代码19 项目: Hify   文件: Config.java
@RequiresApi(api = Build.VERSION_CODES.O)
public static void createNotificationChannels(Context context){

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

    List<NotificationChannelGroup> notificationChannelGroups=new ArrayList<>();
    notificationChannelGroups.add(new NotificationChannelGroup("hify","Hify"));
    notificationChannelGroups.add(new NotificationChannelGroup("other","Other"));

    notificationManager.createNotificationChannelGroups(notificationChannelGroups);

    NotificationChannel flash_message_channel=new NotificationChannel("flash_message","Flash Messages",NotificationManager.IMPORTANCE_HIGH);
    flash_message_channel.enableLights(true);
    flash_message_channel.enableVibration(true);
    flash_message_channel.setGroup("hify");
    flash_message_channel.setSound(Uri.parse("android.resource://"+context.getPackageName()+"/"+ R.raw.hify_sound), null);

    NotificationChannel comments_channel=new NotificationChannel("comments_channel","Comments",NotificationManager.IMPORTANCE_HIGH);
    comments_channel.enableLights(true);
    comments_channel.enableVibration(true);
    comments_channel.setGroup("hify");
    comments_channel.setSound(Uri.parse("android.resource://"+context.getPackageName()+"/"+ R.raw.hify_sound), null);


    NotificationChannel like_channel=new NotificationChannel("like_channel","Likes",NotificationManager.IMPORTANCE_HIGH);
    like_channel.enableLights(true);
    like_channel.enableVibration(true);
    like_channel.setGroup("hify");
    like_channel.setSound(Uri.parse("android.resource://"+context.getPackageName()+"/"+ R.raw.hify_sound), null);

    NotificationChannel forum_channel=new NotificationChannel("forum_channel","Forum",NotificationManager.IMPORTANCE_HIGH);
    forum_channel.enableLights(true);
    forum_channel.enableVibration(true);
    forum_channel.setGroup("hify");
    forum_channel.setSound(Uri.parse("android.resource://"+context.getPackageName()+"/"+ R.raw.hify_sound), null);

    NotificationChannel sending_channel=new NotificationChannel("sending_channel","Sending Media",NotificationManager.IMPORTANCE_LOW);
    sending_channel.enableLights(true);
    sending_channel.enableVibration(true);
    sending_channel.setGroup("other");

    NotificationChannel other_channel=new NotificationChannel("other_channel","Other Notifications",NotificationManager.IMPORTANCE_LOW);
    other_channel.enableLights(true);
    other_channel.enableVibration(true);
    other_channel.setGroup("other");

    NotificationChannel hify_other_channel=new NotificationChannel("hify_other_channel","Other Notifications",NotificationManager.IMPORTANCE_LOW);
    hify_other_channel.enableLights(true);
    hify_other_channel.enableVibration(true);
    hify_other_channel.setGroup("hify");
    hify_other_channel.setSound(Uri.parse("android.resource://"+context.getPackageName()+"/"+ R.raw.hify_sound), null);

    List<NotificationChannel> notificationChannels=new ArrayList<>();
    notificationChannels.add(flash_message_channel);
    notificationChannels.add(like_channel);
    notificationChannels.add(comments_channel);
    notificationChannels.add(forum_channel);
    notificationChannels.add(sending_channel);
    notificationChannels.add(other_channel);
    notificationChannels.add(hify_other_channel);

    notificationManager.createNotificationChannels(notificationChannels);

}
 
源代码20 项目: RelaxFinger   文件: FloatViewManager.java
private void createShowNotification() {

        NotificationManager mNF = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            String name = "com_hardwork_fg607_relaxfinger_channel";
            String id = "悬浮助手";
            String description = "悬浮助手channel";

            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(id, name, importance);
            mChannel.setDescription(description);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
            mNF.createNotificationChannel(mChannel);

            mBuilder =
                    new NotificationCompat.Builder(mContext,id)
                            .setSmallIcon(R.mipmap.ic_launcher)
                            .setContentTitle("RelaxFinger")
                            .setTicker("悬浮球隐藏到通知栏啦,点击显示!")
                            .setContentText("点击显示悬浮球");

        }else{

             mBuilder =
                    new NotificationCompat.Builder(mContext)
                            .setSmallIcon(R.mipmap.ic_launcher)
                            .setContentTitle("RelaxFinger")
                            .setTicker("悬浮球隐藏到通知栏啦,点击显示!")
                            .setContentText("点击显示悬浮球");

        }

        Intent resultIntent = new Intent(Config.ACTION_SHOW_FLOATBALL);

        PendingIntent resultPendingIntent = PendingIntent.getBroadcast(mContext,(int) SystemClock.uptimeMillis(), resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(resultPendingIntent);


        Notification notification = mBuilder.build();

        notification.flags |= Notification.FLAG_NO_CLEAR;

        mNF.notify(R.string.app_name, notification);

    }