Java Code Examples for android.app.NotificationManager#IMPORTANCE_HIGH

The following examples show how to use android.app.NotificationManager#IMPORTANCE_HIGH . 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: Notifier.java    From AndroidGodEye with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: MobileMessagingCore.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: TestCaseListActivity.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
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);
}
 
Example 4
Source File: EarthquakeUpdateJobService.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 5
Source File: ChatFirebaseMessagingService.java    From chat21-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 6
Source File: RCDevice.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: NotificationChannels.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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");
    }
}
 
Example 8
Source File: NotificationStatusBarActivity.java    From coursera-android with MIT License 5 votes vote down vote up
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);
}
 
Example 9
Source File: ImagePipelineNotificationFragment.java    From fresco with MIT License 5 votes vote down vote up
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);
}
 
Example 10
Source File: WarningHelper.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 11
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 12
Source File: KeepAppAliveService.java    From PLDroidMediaStreaming with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 13
Source File: MyActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 14
Source File: EarthquakeUpdateJobService.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 15
Source File: FIRMessagingModule.java    From react-native-fcm with MIT License 4 votes vote down vote up
@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);
}
 
Example 16
Source File: NotificationHelper.java    From PermissionEverywhere with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 17
Source File: NotificationSupport.java    From android with MIT License 4 votes vote down vote up
@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);
    }
}
 
Example 18
Source File: PushListenerService.java    From android_sdk_demo_apps with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 19
Source File: Config.java    From Hify with MIT License 4 votes vote down vote up
@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);

}
 
Example 20
Source File: FloatViewManager.java    From RelaxFinger with GNU General Public License v2.0 2 votes vote down vote up
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);

    }