Java 类android.app.NotificationChannel 实例源码

项目:LaunchEnr    文件:NotificationListener.java   
private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
    Notification notification = sbn.getNotification();

    if (AndroidVersion.isAtLeastOreo()) {
        getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
        if (!mTempRanking.canShowBadge()) {
            return true;
        }
        if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            // Special filtering for the default, legacy "Miscellaneous" channel.
            if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
                return true;
            }
        }
    }

    if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
        return true;
    }

    boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
    CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
    CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
    boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
    return (isGroupHeader || missingTitleAndText);
}
项目:KernelAdiutor-Mod    文件:ApplyOnBootService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
                getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.setSound(null, null);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder builder = new Notification.Builder(
                this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.apply_on_boot))
                .setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationId.APPLY_ON_BOOT, builder.build());
    }
}
项目:NovaMusicPlayer    文件:NovaNotificationManager.java   
private void createNotificationChannelForAndroidO() {
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && mNotificationManager != null) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                "Nova Music Player", NotificationManager.IMPORTANCE_LOW);

        // Configure the notification channel.
        notificationChannel.setDescription("Channel of Nova Music Player");
        notificationChannel.enableLights(false);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
        notificationChannel.setSound(null, null);
        notificationChannel.enableVibration(false);
        notificationChannel.setShowBadge(false);
        mNotificationManager.createNotificationChannel(notificationChannel);
    }
}
项目:android-mobile-engage-sdk    文件:MessagingServiceUtilsTest.java   
@Test
@SdkSuppress(minSdkVersion = O)
public void testCreateChannel_overridesPrevious(){
    NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.deleteNotificationChannel("ems_me_default");
    assertNull(manager.getNotificationChannel("ems_me_default"));
    MessagingServiceUtils.createDefaultChannel(context, enabledOreoConfig);
    NotificationChannel channel = manager.getNotificationChannel("ems_me_default");
    assertNotNull(channel);

    OreoConfig updatedConfig = new OreoConfig(true, "updatedName", "updatedDescription");
    MessagingServiceUtils.createDefaultChannel(context, updatedConfig);

    NotificationChannel updatedChannel = manager.getNotificationChannel("ems_me_default");
    assertEquals(updatedConfig.getDefaultChannelName(), updatedChannel.getName());
    assertEquals(updatedConfig.getDefaultChannelDescription(), updatedChannel.getDescription());
}
项目:BlueBolt-Kernel-Tweaking-app    文件:ProximityService.java   
@Override
public void onCreate(){
    if(DEBUG) Log.i(TAG,"Service Started");
    proximitySensorDetails = new ProximitySensorDetails(this);

    IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenStateReceiver, screenStateFilter);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL, "BlueBolt Pocket Mode", NotificationManager.IMPORTANCE_UNSPECIFIED);
        notificationManager.createNotificationChannel(notificationChannel);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, SplashActivity.class), 0);

        Notification.Builder builder = new Notification.Builder(this, CHANNEL);
        builder.setContentTitle(notificationTitle)
                .setContentText(notificationText)
                .setSmallIcon(R.mipmap.ic_launcher_foreground)
                .setContentIntent(pendingIntent)
                .setOngoing(true);

        if(DEBUG) Log.i(TAG,"Notification Created");
        startForeground(1, builder.build());
    }

}
项目:VBrowser-Android    文件:DownloadForegroundService.java   
@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(){
    String channelId = "VBrowserNotification";
    String channelName = "前台下载通知";
    NotificationChannel chan = new NotificationChannel(channelId,
            channelName, NotificationManager.IMPORTANCE_HIGH);
    chan.setLightColor(Color.BLUE);
    chan.setImportance(NotificationManager.IMPORTANCE_NONE);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
    return channelId;
}
项目:Aequorea    文件:CacheService.java   
private void showNotification() {
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, getString(R.string.aequorea_offline_cache), NotificationManager.IMPORTANCE_DEFAULT);
        mNotificationManager.createNotificationChannel(channel);
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID).setSmallIcon(R.mipmap.ic_notification)
        .setContentTitle(getString(R.string.app_name))
        .setContentText(getString(R.string.caching_offline_article));

    if (mNotificationManager != null) {
        mNotificationManager.notify(1, builder.build());
    }
}
项目:GPSTracker-Android    文件:NotificationClass.java   
@RequiresApi(Build.VERSION_CODES.O)
public void createMainNotificationChannel(Context c) {
    String id = CHANNEL_ID;
    String name = CHANNEL_NAME;
    String description = CHANNEL_DESCRIPTION;
    int importance = NotificationManager.IMPORTANCE_LOW;
    NotificationChannel mChannel = new NotificationChannel(id, name, importance);
    mChannel.setDescription (description);
    mChannel.enableLights(true);
    mChannel.setLightColor( Color.RED);
    mChannel.enableVibration(true);
    NotificationManager mNotificationManager =
            (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
   // NotificationManager mNotificationManager = c.getSystemService(Context.NOTIFICATION_SERVICE) as android.app.NotificationManager
    mNotificationManager.createNotificationChannel(mChannel);
}
项目:AgentWeb    文件:Notify.java   
public Notify(Context context, int ID) {
    this.NOTIFICATION_ID = ID;
    mContext = context;
    // 获取系统服务来初始化对象
    nm = (NotificationManager) mContext
            .getSystemService(NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        cBuilder = new NotificationCompat.Builder(mContext, mChannelId = mContext.getPackageName().concat(AGENTWEB_VERSION));
        NotificationChannel mNotificationChannel = new NotificationChannel(mChannelId, AgentWebUtils.getApplicationName(context), NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
        mNotificationManager.createNotificationChannel(mNotificationChannel);
    } else {
        cBuilder = new NotificationCompat.Builder(mContext);
    }
}
项目:Sherlock    文件:CrashReporter.java   
public void report(CrashViewModel crashViewModel) {
  Notification notification = notification(crashViewModel);

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

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(
        CHANNEL_ID,
        "Sherlock",
        IMPORTANCE_DEFAULT
    );
    notificationManager.createNotificationChannel(channel);
  }

  notificationManager.notify(crashViewModel.getIdentifier(), notification);
}
项目:MiPushFramework    文件:KeepAliveService.java   
public @StartResult int onStartCommand(Intent intent, @StartArgFlags int flags, int startId) {
    NotificationManager manager = (NotificationManager)
            getSystemService(NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_STATUS,
                getString(R.string.notification_category_alive),
                NotificationManager.IMPORTANCE_MIN);
        manager.createNotificationChannel(channel);
    }
    Notification notification = new NotificationCompat.Builder(this,
            CHANNEL_STATUS)
            .setContentTitle(getString(R.string.notification_alive))
            .setSmallIcon(R.mipmap.ic_app)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setOngoing(true)
            .build();
    manager.notify(NOTIFICATION_ALIVE_ID, notification);
    startForeground(NOTIFICATION_ALIVE_ID, notification);
    return START_STICKY;
}
项目:MTweaks-KernelAdiutorMOD    文件:ApplyOnBootService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,
                getString(R.string.apply_on_boot), NotificationManager.IMPORTANCE_DEFAULT);
        notificationChannel.setSound(null, null);
        notificationManager.createNotificationChannel(notificationChannel);

        Notification.Builder builder = new Notification.Builder(
                this, CHANNEL_ID);
        builder.setContentTitle(getString(R.string.apply_on_boot))
                .setSmallIcon(R.mipmap.ic_launcher);
        startForeground(NotificationId.APPLY_ON_BOOT, builder.build());
    }
}
项目:fitnotifications    文件:HomeActivity.java   
private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        String id = Constants.NOTIFICATION_CHANNEL_ID;
        CharSequence name = getString(R.string.notification_channel_name);
        String desc = getString(R.string.notification_channel_desc);
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel channel = new NotificationChannel(id, name, importance);
        channel.setShowBadge(false);
        channel.setDescription(desc);
        channel.enableLights(false);
        channel.enableVibration(false);
        manager.createNotificationChannel(channel);
    }

}
项目:chalkboard    文件:Background.java   
@TargetApi(26)
private void createNotificationChannel() {

    notificationChannelClass = new NotificationChannel("class", "Class Notifications", NotificationManager.IMPORTANCE_LOW);
    notificationChannelClass.setDescription("Notifications about classes.");
    notificationChannelClass.enableLights(false);
    notificationChannelClass.enableVibration(false);
    notificationChannelClass.setBypassDnd(false);
    notificationChannelClass.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelClass.setShowBadge(false);

    notificationManager.createNotificationChannel(notificationChannelClass);

    notificationChannelReminder = new NotificationChannel("reminder", "Reminders", NotificationManager.IMPORTANCE_MAX);
    notificationChannelReminder.setDescription("Notifications about events.");
    notificationChannelReminder.enableLights(true);
    notificationChannelReminder.setLightColor(sharedPreferences.getInt("primary_color", ContextCompat.getColor(this, R.color.teal)));
    notificationChannelReminder.enableVibration(true);
    notificationChannelReminder.setBypassDnd(true);
    notificationChannelReminder.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    notificationChannelReminder.setShowBadge(true);

    notificationManager.createNotificationChannel(notificationChannelReminder);

}
项目:android-NotificationChannels    文件:NotificationHelper.java   
/**
 * Registers notification channels, which can be used later by individual notifications.
 *
 * @param ctx The application context
 */
public NotificationHelper(Context ctx) {
    super(ctx);

    NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL,
            getString(R.string.noti_channel_default), NotificationManager.IMPORTANCE_DEFAULT);
    chan1.setLightColor(Color.GREEN);
    chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    getManager().createNotificationChannel(chan1);

    NotificationChannel chan2 = new NotificationChannel(SECONDARY_CHANNEL,
            getString(R.string.noti_channel_second), NotificationManager.IMPORTANCE_HIGH);
    chan2.setLightColor(Color.BLUE);
    chan2.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    getManager().createNotificationChannel(chan2);
}
项目:mediasession-mediaplayer    文件:MediaNotificationManager.java   
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel() {
    if (mNotificationManager.getNotificationChannel(CHANNEL_ID) == null) {
        // The user-visible name of the channel.
        CharSequence name = "MediaSession";
        // The user-visible description of the channel.
        String description = "MediaSession and MediaPlayer";
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, 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(
                new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mNotificationManager.createNotificationChannel(mChannel);
        Log.d(TAG, "createChannel: New channel created");
    } else {
        Log.d(TAG, "createChannel: Existing channel reused");
    }
}
项目:Goalie_Android    文件:MessagingService.java   
private String getNotificationChannelID() {
    final String channelID = "GoalieChannelID";

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        CharSequence name = getString(R.string.app_name);
        String description = getString(R.string.channel_description);
        int importance = NotificationManager.IMPORTANCE_HIGH;

        NotificationChannel mChannel = new NotificationChannel(channelID, name, importance);
        mChannel.setDescription(description);
        mChannel.enableLights(true);
        mChannel.enableVibration(true);
        mNotificationManager.createNotificationChannel(mChannel);
    }

    return channelID;
}
项目:okwallet    文件:WalletApplication.java   
private void initNotificationManager() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final Stopwatch watch = Stopwatch.createStarted();
        final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        final NotificationChannel received = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_RECEIVED,
                getString(R.string.notification_channel_received_name), NotificationManager.IMPORTANCE_DEFAULT);
        received.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received),
                new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build());
        nm.createNotificationChannel(received);

        final NotificationChannel ongoing = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_ONGOING,
                getString(R.string.notification_channel_ongoing_name), NotificationManager.IMPORTANCE_LOW);
        nm.createNotificationChannel(ongoing);

        final NotificationChannel important = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_IMPORTANT,
                getString(R.string.notification_channel_important_name), NotificationManager.IMPORTANCE_HIGH);
        nm.createNotificationChannel(important);

        log.info("created notification channels, took {}", watch);
    }
}
项目:PlayAndroid    文件:MediaNotificationManager.java   
@RequiresApi(Build.VERSION_CODES.O)
private void createChannel() {
    if (mNotificationManager.getNotificationChannel(CHANNEL_ID) == null) {
        // The user-visible name of the channel.
        CharSequence name = "MediaSession";
        // The user-visible description of the channel.
        String description = "MediaSession and MediaPlayer";
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, 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(
                new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mNotificationManager.createNotificationChannel(mChannel);
        Log.d(TAG, "createChannel: New channel created");
    } else {
        Log.d(TAG, "createChannel: Existing channel reused");
    }
}
项目:TherapyGuide    文件:NotificationHandler.java   
public static void createNotificationChannels(Context context) {

        if(android.os.Build.VERSION.SDK_INT >= 26) {

            NotificationChannel diaryChannel = new NotificationChannel(
                    NOTIFICATION_CHANNEL_ID_DIARY,
                    context.getString(R.string.diary_reminder_notification_channel_name),
                    NotificationManager.IMPORTANCE_HIGH);
            diaryChannel.setDescription(context.getString(R.string.diary_reminder_notification_channel_description));

            NotificationChannel playerChannel = new NotificationChannel(
                    NOTIFICATION_CHANNEL_ID_PLAYER,
                    context.getString(R.string.player_notification_channel_name),
                    NotificationManager.IMPORTANCE_DEFAULT);
            playerChannel.setDescription(context.getString(R.string.player_notification_channel_description));

            // Create channels
            NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(diaryChannel);
            notificationManager.createNotificationChannel(playerChannel);
        }

    }
项目:TherapyGuide    文件:NotificationHandlerTest.java   
@TargetApi(26)
@Test
public void createNotificationChannels_createsCorrectChannels() {

    try {
        setFinalStatic(Build.VERSION.class.getField("SDK_INT"), 26);
    } catch (Exception e) {
        e.printStackTrace();
    }
    when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(mNotificationManager);
    when(mContext.getString(R.string.diary_reminder_notification_channel_name)).thenReturn("Diary Reminder");
    when(mContext.getString(R.string.player_notification_channel_name)).thenReturn("Player");

    NotificationHandler.createNotificationChannels(mContext);

    verify(mNotificationManager, times(2)).createNotificationChannel(any(NotificationChannel.class));
}
项目:malp    文件:NotificationManager.java   
/**
 * Creates the {@link NotificationChannel} for devices running Android O or higher
 */
private void openChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, mService.getResources().getString(R.string.notification_channel_name_playback), android.app.NotificationManager.IMPORTANCE_LOW);
        // Disable lights & vibration
        channel.enableVibration(false);
        channel.enableLights(false);
        channel.setVibrationPattern(null);

        // Allow lockscreen playback control
        channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);

        // Register the channel
        mNotificationManager.createNotificationChannel(channel);
    }
}
项目:rview    文件:NotificationsHelper.java   
@TargetApi(Build.VERSION_CODES.O)
public static void createNotificationChannel(Context context, Account account) {
    if (AndroidHelper.isApi26OrGreater()) {
        final String defaultChannelName = context.getString(
                R.string.notifications_default_channel_name,
                account.getRepositoryDisplayName(), account.getAccountDisplayName());
        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.createNotificationChannelGroup(new NotificationChannelGroup(
                account.getAccountHash(), defaultChannelName));

        NotificationChannel channel = new NotificationChannel(account.getAccountHash(),
                defaultChannelName, NotificationManager.IMPORTANCE_DEFAULT);
        channel.setDescription(context.getString(R.string.notifications_default_channel_description));
        channel.enableVibration(true);
        channel.enableLights(true);
        channel.setLightColor(ContextCompat.getColor(context, R.color.primaryDark));
        channel.setShowBadge(true);
        channel.setGroup(account.getAccountHash());
        nm.createNotificationChannel(channel);
    }
}
项目:niddler    文件:OreoCompatHelper.java   
public static String createNotificationChannel(@NonNull final Context context) {
    final NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return "";
    }

    final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
    channel.setDescription(CHANNEL_DESCRIPTION);
    channel.enableLights(false);
    channel.enableVibration(false);
    channel.setBypassDnd(false);
    channel.setShowBadge(false);
    channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);

    notificationManager.createNotificationChannel(channel);
    return CHANNEL_ID;
}
项目:Applozic-Android-Chat-Sample    文件:RegisterUserClientService.java   
@RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence name = MobiComKitConstants.PUSH_NOTIFICATION_NAME;
    ;
    int importance = NotificationManager.IMPORTANCE_HIGH;
    if (mNotificationManager.getNotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION) == null) {
        NotificationChannel mChannel = new NotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION, name, importance);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.GREEN);
        if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
            mChannel.setShowBadge(true);
        } else {
            mChannel.setShowBadge(false);
        }
        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_RINGTONE).build();
        mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), audioAttributes);
        mNotificationManager.createNotificationChannel(mChannel);

    }

}
项目:focus-android    文件:SessionNotificationService.java   
public void createNotificationChannelIfNeeded() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        // Notification channels are only available on Android O or higher.
        return;
    }

    final NotificationManager notificationManager = getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }

    final String notificationChannelName = getString(R.string.notification_browsing_session_channel_name);
    final String notificationChannelDescription = getString(
            R.string.notification_browsing_session_channel_description,
            getString(R.string.app_name));

    final NotificationChannel channel = new NotificationChannel(
            NOTIFICATION_CHANNEL_ID, notificationChannelName, NotificationManager.IMPORTANCE_MIN);
    channel.setImportance(NotificationManager.IMPORTANCE_LOW);
    channel.setDescription(notificationChannelDescription);
    channel.enableLights(false);
    channel.enableVibration(false);
    channel.setShowBadge(true);

    notificationManager.createNotificationChannel(channel);
}
项目:dns66    文件:NotificationChannels.java   
public static void onCreate(Context context) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;

    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(GROUP_SERVICE, context.getString(R.string.notifications_group_service)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(GROUP_UPDATE, context.getString(R.string.notifications_group_updates)));

    NotificationChannel runningChannel = new NotificationChannel(SERVICE_RUNNING, context.getString(R.string.notifications_running), NotificationManager.IMPORTANCE_MIN);
    runningChannel.setDescription(context.getString(R.string.notifications_running_desc));
    runningChannel.setGroup(GROUP_SERVICE);
    runningChannel.setShowBadge(false);
    notificationManager.createNotificationChannel(runningChannel);

    NotificationChannel pausedChannel = new NotificationChannel(SERVICE_PAUSED, context.getString(R.string.notifications_paused), NotificationManager.IMPORTANCE_LOW);
    pausedChannel.setDescription(context.getString(R.string.notifications_paused_desc));
    pausedChannel.setGroup(GROUP_SERVICE);
    pausedChannel.setShowBadge(false);
    notificationManager.createNotificationChannel(pausedChannel);

    NotificationChannel updateChannel = new NotificationChannel(UPDATE_STATUS, context.getString(R.string.notifications_update), NotificationManager.IMPORTANCE_LOW);
    updateChannel.setDescription(context.getString(R.string.notifications_update_desc));
    updateChannel.setGroup(GROUP_UPDATE);
    updateChannel.setShowBadge(false);
    notificationManager.createNotificationChannel(updateChannel);
}
项目:xDrip    文件:NotificationChannels.java   
@TargetApi(26)
private static int myhashcode(NotificationChannel x) {

    int result = x.getId() != null ? x.getId().hashCode() : 0;
    //result = 31 * result + (getName() != null ? getName().hashCode() : 0);
    //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0);
    //result = 31 * result + getImportance();
    //result = 31 * result + (mBypassDnd ? 1 : 0);
    //result = 31 * result + getLockscreenVisibility();
    result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0);
    //result = 31 * result + (x.mLights ? 1 : 0);
    result = 31 * result + x.getLightColor();
    result = 31 * result + Arrays.hashCode(x.getVibrationPattern());
    //result = 31 * result + getUserLockedFields();
    //result = 31 * result + (mVibrationEnabled ? 1 : 0);
    //result = 31 * result + (mShowBadge ? 1 : 0);
    //result = 31 * result + (isDeleted() ? 1 : 0);
    //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0);
    //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0);
    //result = 31 * result + (isBlockableSystem() ? 1 : 0);
    return result;

}
项目:xDrip    文件:NotificationChannels.java   
@TargetApi(26)
public static boolean isSoundDifferent(String id, NotificationChannel x) {
    if (x.getSound() == null) return false; // this does not have a sound
    final NotificationChannel c = getNotifManager().getNotificationChannel(id);
    if (c == null) return false; // no channel with this id
    if (c.getSound() == null)
        return false; // this maybe will only happen if user disables sound so lets not create a new one in that case

    final String original_sound = PersistentStore.getString("original-channel-sound-" + id);
    if (original_sound.equals("")) {
        PersistentStore.setString("original-channel-sound-" + id, x.getSound().toString());
        return false; // no existing record so save the original and do nothing else
    }
    if (original_sound.equals(x.getSound().toString()))
        return false; // its the same sound still
    return true; // the sound has changed vs the original
}
项目:GeometricWeather    文件:NotificationUtils.java   
private static void sendAlertNotification(Context c, String cityName, Alert alert) {
    NotificationManager manager = ((NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE));
    if (manager != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(
                    CHANNEL_ID_ALERT,
                    c.getString(R.string.app_name) + " " + c.getString(R.string.action_alert),
                    NotificationManager.IMPORTANCE_DEFAULT);
            channel.setShowBadge(true);
            manager.createNotificationChannel(channel);
        }
        manager.notify(
                getNotificationId(c),
                buildSingleNotification(c, cityName, alert));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            manager.notify(NOTIFICATION_GROUP_SUMMARY_ID, buildGroupSummaryNotification(c, cityName, alert));
        }
    }
}
项目:xDrip-plus    文件:NotificationChannels.java   
@TargetApi(26)
private static int myhashcode(NotificationChannel x) {

    int result = x.getId() != null ? x.getId().hashCode() : 0;
    //result = 31 * result + (getName() != null ? getName().hashCode() : 0);
    //result = 31 * result + (getDescription() != null ? getDescription().hashCode() : 0);
    //result = 31 * result + getImportance();
    //result = 31 * result + (mBypassDnd ? 1 : 0);
    //result = 31 * result + getLockscreenVisibility();
    result = 31 * result + (x.getSound() != null ? x.getSound().hashCode() : 0);
    //result = 31 * result + (x.mLights ? 1 : 0);
    result = 31 * result + x.getLightColor();
    result = 31 * result + Arrays.hashCode(x.getVibrationPattern());
    //result = 31 * result + getUserLockedFields();
    //result = 31 * result + (mVibrationEnabled ? 1 : 0);
    //result = 31 * result + (mShowBadge ? 1 : 0);
    //result = 31 * result + (isDeleted() ? 1 : 0);
    //result = 31 * result + (getGroup() != null ? getGroup().hashCode() : 0);
    //result = 31 * result + (getAudioAttributes() != null ? getAudioAttributes().hashCode() : 0);
    //result = 31 * result + (isBlockableSystem() ? 1 : 0);
    return result;

}
项目:xDrip-plus    文件:NotificationChannels.java   
@TargetApi(26)
public static boolean isSoundDifferent(String id, NotificationChannel x) {
    if (x.getSound() == null) return false; // this does not have a sound
    final NotificationChannel c = getNotifManager().getNotificationChannel(id);
    if (c == null) return false; // no channel with this id
    if (c.getSound() == null)
        return false; // this maybe will only happen if user disables sound so lets not create a new one in that case

    final String original_sound = PersistentStore.getString("original-channel-sound-" + id);
    if (original_sound.equals("")) {
        PersistentStore.setString("original-channel-sound-" + id, x.getSound().toString());
        return false; // no existing record so save the original and do nothing else
    }
    if (original_sound.equals(x.getSound().toString()))
        return false; // its the same sound still
    return true; // the sound has changed vs the original
}
项目:TrebleShot    文件:NotificationUtils.java   
public NotificationUtils(Context context)
{
    mContext = context;
    mManager = NotificationManagerCompat.from(context);
    mDatabase = new AccessDatabase(context);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationChannel channelHigh = new NotificationChannel(NOTIFICATION_CHANNEL_HIGH, mContext.getString(R.string.text_appName), NotificationManager.IMPORTANCE_HIGH);
        channelHigh.enableLights(mPreferences.getBoolean("notification_light", false));
        channelHigh.enableVibration(mPreferences.getBoolean("notification_vibrate", false));
        notificationManager.createNotificationChannel(channelHigh);

        NotificationChannel channelLow = new NotificationChannel(NOTIFICATION_CHANNEL_LOW, mContext.getString(R.string.text_appName), NotificationManager.IMPORTANCE_NONE);
        notificationManager.createNotificationChannel(channelLow);
    }
}
项目:kcanotify    文件:KcaAlarmService.java   
private void createAlarmChannel(String uri) {
    Log.e("KCA-A", "recv: " + uri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
        boolean isVibrate = soundKind.equals(getString(R.string.sound_kind_value_mixed)) || soundKind.equals(getString(R.string.sound_kind_value_vibrate));
        notificationManager.deleteNotificationChannel(ALARM_CHANNEL_ID);
        while (!alarmChannelList.isEmpty()) {
            notificationManager.deleteNotificationChannel(alarmChannelList.poll());
        }

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

        String channel_name = createAlarmId(uri, isVibrate);
        alarmChannelList.add(channel_name);
        NotificationChannel channel = new NotificationChannel(alarmChannelList.peek(),
                getStringWithLocale(R.string.notification_appinfo_title), NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(Uri.parse(uri), attrs.build());
        channel.enableVibration(isVibrate);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        notificationManager.createNotificationChannel(channel);
    }
}
项目:NMAkademija    文件:NMAFirebaseMessagingService.java   
@Override
public void onCreate() {
    super.onCreate();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationChannel notificationChannel =
                new NotificationChannel(
                        CHANNEL_ID,
                        getString(R.string.notifications),
                        NotificationManager.IMPORTANCE_DEFAULT);

        notificationManager.createNotificationChannel(notificationChannel);
    }
}
项目:mobile-messaging-sdk-android    文件:MobileMessagingCore.java   
private void initDefaultChannel() {
    if (Build.VERSION.SDK_INT < 26) {
        return;
    }
    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (notificationManager == null) {
        return;
    }

    final CharSequence channelName = SoftwareInformation.getAppName(context);
    final int importance = NotificationManager.IMPORTANCE_DEFAULT;
    final NotificationChannel notificationChannel = new NotificationChannel(MM_DEFAULT_CHANNEL_ID, channelName, importance);
    notificationChannel.enableLights(true);
    notificationChannel.enableVibration(true);
    notificationManager.createNotificationChannel(notificationChannel);
}
项目:odyssey    文件:OdysseyNotificationManager.java   
/**
 * Creates the {@link NotificationChannel} for devices running Android O or higher
 */
private void openChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, mContext.getResources().getString(R.string.notification_channel_playback), android.app.NotificationManager.IMPORTANCE_LOW);
        // Disable lights & vibration
        channel.enableVibration(false);
        channel.enableLights(false);
        channel.setVibrationPattern(null);

        // Allow lockscreen playback control
        channel.setLockscreenVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC);

        // Register the channel
        mNotificationManager.createNotificationChannel(channel);
    }
}
项目:trackbook    文件:NotificationHelper.java   
public static boolean createNotificationChannel(Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // API level 26 ("Android O") supports notification channels.
            String id = NOTIFICATION_CHANEL_ID_RECORDING_CHANNEL;
            CharSequence name = context.getString(R.string.notification_channel_recording_name);
            String description = context.getString(R.string.notification_channel_recording_description);
            int importance = NotificationManager.IMPORTANCE_LOW;

            // create channel
            NotificationChannel channel = new NotificationChannel(id, name, importance);
            channel.setDescription(description);

            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(channel);
            return true;

        } else {
            return false;
        }
    }
项目:Blackbulb    文件:BlackbulbApplication.java   
@TargetApi(Build.VERSION_CODES.O)
public void createNotificationChannel() {
    NotificationManager notificationManager = getSystemService(NotificationManager.class);
    if (notificationManager != null) {
        NotificationChannel channel = new NotificationChannel(
                Constants.NOTIFICATION_CHANNEL_ID_RS,
                getString(R.string.notification_channel_running_status),
                NotificationManager.IMPORTANCE_DEFAULT
        );
        channel.setShowBadge(false);
        channel.enableLights(false);
        channel.enableVibration(false);
        channel.setSound(null, null);

        notificationManager.createNotificationChannel(channel);
    }
}
项目:Hover    文件:BaseWindow.java   
@Override
protected void onCreate(@Nullable Bundle arguments) {
    super.onCreate(arguments);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                "Floating windows", NotificationManager.IMPORTANCE_DEFAULT);

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

        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }
    }
}