Example usage for android.app NotificationChannel enableVibration

List of usage examples for android.app NotificationChannel enableVibration

Introduction

In this page you can find the example usage for android.app NotificationChannel enableVibration.

Prototype

public void enableVibration(boolean vibration) 

Source Link

Document

Sets whether notification posted to this channel should vibrate.

Usage

From source file:com.none.tom.simplerssreader.service.FeedUpdateBackgroundService.java

@SuppressWarnings({ "ConstantConditions", "deprecation" })
private static void showNotification(final Context context, final List<String> payload) {
    final NotificationManager manager = context.getSystemService(NotificationManager.class);

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

        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        channel.setBypassDnd(false);/*ww w . j  a v a 2 s .co m*/
        channel.enableLights(true);
        channel.setShowBadge(true);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
    }

    final PendingIntent intent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
            .setBigContentTitle(context.getString(R.string.notification_title_big));

    final int size = payload.size();

    for (int i = 0; i < size; i++) {
        style.addLine(payload.get(i));
    }

    manager.notify(ID_NOTIFICATION, new NotificationCompat.Builder(context)
            .setChannelId(NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_rss_feed_white_24dp)
            .setContentTitle(context.getString(R.string.notification_title))
            .setContentText(context.getString(R.string.notification_text)).setContentIntent(intent)
            .setStyle(style).setWhen(System.currentTimeMillis()).setAutoCancel(true).setShowWhen(true).build());
}

From source file:com.keylesspalace.tusky.util.NotificationManager.java

public static void createNotificationChannels(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

        android.app.NotificationManager mNotificationManager = (android.app.NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        String[] channelIds = new String[] { CHANNEL_MENTION, CHANNEL_FOLLOW, CHANNEL_BOOST,
                CHANNEL_FAVOURITE };/*w w  w.j av a  2 s  .c om*/
        int[] channelNames = { R.string.notification_channel_mention_name,
                R.string.notification_channel_follow_name, R.string.notification_channel_boost_name,
                R.string.notification_channel_favourite_name };
        int[] channelDescriptions = { R.string.notification_channel_mention_descriptions,
                R.string.notification_channel_follow_description,
                R.string.notification_channel_boost_description,
                R.string.notification_channel_favourite_description };

        List<NotificationChannel> channels = new ArrayList<>(4);

        for (int i = 0; i < channelIds.length; i++) {
            String id = channelIds[i];
            String name = context.getString(channelNames[i]);
            String description = context.getString(channelDescriptions[i]);
            int importance = android.app.NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(id, name, importance);

            channel.setDescription(description);
            channel.enableLights(true);
            channel.enableVibration(true);
            channel.setShowBadge(true);
            channels.add(channel);
        }

        //noinspection ConstantConditions
        mNotificationManager.createNotificationChannels(channels);

    }
}

From source file:com.ruesga.rview.misc.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);//  w  w  w  .j av  a2s  .c  o  m
        channel.setLightColor(ContextCompat.getColor(context, R.color.primaryDark));
        channel.setShowBadge(true);
        channel.setGroup(account.getAccountHash());
        nm.createNotificationChannel(channel);
    }
}

From source file:com.keylesspalace.tusky.util.NotificationHelper.java

public static void createNotificationChannelsForAccount(@NonNull AccountEntity account,
        @NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

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

        String[] channelIds = new String[] { CHANNEL_MENTION + account.getIdentifier(),
                CHANNEL_FOLLOW + account.getIdentifier(), CHANNEL_BOOST + account.getIdentifier(),
                CHANNEL_FAVOURITE + account.getIdentifier() };
        int[] channelNames = { R.string.notification_channel_mention_name,
                R.string.notification_channel_follow_name, R.string.notification_channel_boost_name,
                R.string.notification_channel_favourite_name };
        int[] channelDescriptions = { R.string.notification_channel_mention_descriptions,
                R.string.notification_channel_follow_description,
                R.string.notification_channel_boost_description,
                R.string.notification_channel_favourite_description };

        List<NotificationChannel> channels = new ArrayList<>(4);

        NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(),
                account.getFullName());/*w ww.  j  av a2s  .  c  om*/

        //noinspection ConstantConditions
        notificationManager.createNotificationChannelGroup(channelGroup);

        for (int i = 0; i < channelIds.length; i++) {
            String id = channelIds[i];
            String name = context.getString(channelNames[i]);
            String description = context.getString(channelDescriptions[i]);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(id, name, importance);

            channel.setDescription(description);
            channel.enableLights(true);
            channel.setLightColor(0xFF2B90D9);
            channel.enableVibration(true);
            channel.setShowBadge(true);
            channel.setGroup(account.getIdentifier());
            channels.add(channel);
        }

        //noinspection ConstantConditions
        notificationManager.createNotificationChannels(channels);

    }
}

From source file:chat.viska.android.Application.java

private void initializeNotificationChannels() {
    if (Build.VERSION.SDK_INT >= 26) {
        final NotificationManager manager = getSystemService(NotificationManager.class);

        final NotificationChannel systemChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_SYSTEM,
                getString(R.string.title_notif_channel_system), NotificationManager.IMPORTANCE_LOW);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_system));
        systemChannel.enableVibration(false);
        systemChannel.enableLights(false);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        systemChannel.setShowBadge(false);
        manager.createNotificationChannel(systemChannel);

        final NotificationChannel messagingChannel = new NotificationChannel(KEY_NOTIF_CHANNEL_MESSAGES,
                getString(R.string.title_notif_channel_messaging), NotificationManager.IMPORTANCE_HIGH);
        systemChannel.setDescription(getString(R.string.desc_notif_channel_messaging));
        systemChannel.enableVibration(true);
        systemChannel.enableLights(true);
        systemChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
        systemChannel.setShowBadge(true);
        manager.createNotificationChannel(messagingChannel);
    }//from   www .  ja  v  a  2  s  . c  o m
}

From source file:org.mozilla.focus.session.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;//from w ww  .ja v a  2  s  . c  o  m
    }

    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);
}

From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java

public void initNotificationChannels() {
    if (android.os.Build.VERSION.SDK_INT >= 26) {
        NotificationChannel pushChannel = new NotificationChannel(PUSH_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.push_notification),
                NotificationManager.IMPORTANCE_HIGH);

        pushChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.push_notification_description));
        pushChannel.enableLights(true);/*from   w w  w. j  av  a  2  s  . c o m*/
        pushChannel.enableVibration(true);
        pushChannel.setShowBadge(true);
        pushChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel persistentChannel = new NotificationChannel(PERSISTENT_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.persistent_notification),
                NotificationManager.IMPORTANCE_MIN);

        persistentChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.persistent_notification_description));
        persistentChannel.enableLights(false);
        persistentChannel.enableVibration(false);
        persistentChannel.setShowBadge(false);
        persistentChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);

        NotificationChannel serviceChannel = new NotificationChannel(SERVICE_NOTIFICATION_CHANNEL,
                ApplicationLoader.applicationContext.getResources().getString(R.string.service_notification),
                NotificationManager.IMPORTANCE_MIN);

        serviceChannel.setDescription(ApplicationLoader.applicationContext.getResources()
                .getString(R.string.service_notification_description));
        serviceChannel.enableLights(false);
        serviceChannel.enableVibration(false);
        serviceChannel.setShowBadge(false);
        serviceChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);

        NotificationManager mManager = (NotificationManager) ApplicationLoader.applicationContext
                .getSystemService(Context.NOTIFICATION_SERVICE);

        mManager.createNotificationChannel(pushChannel);
        mManager.createNotificationChannel(persistentChannel);
        mManager.createNotificationChannel(serviceChannel);
    }
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void appointmentNotification() {
    Appointment[] appointments = calendarDB.getNotificationAppointments();
    Log.d(TAG, "AppointmentNotifications: amount of appointments that should be shown: " + appointments.length);
    String previousAppointment = configUtil.getString("previous_appointment");
    if (appointments.length >= 1) {
        Appointment appointment = appointments[0];
        if (!mGson.toJson(appointment).equals(previousAppointment) && isCandidate(appointment)) {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setSmallIcon(R.drawable.ic_appointment);

            if (appointment.startDate != null) {
                String time = DateUtils.formatDate(appointment.startDate, "HH:mm");
                mBuilder.setContentTitle("Volgende afspraak (" + time + ")");
            } else {
                mBuilder.setContentTitle("Volgende afspraak:");
            }/*from ww w. ja v  a  2s . co  m*/
            mBuilder.setContentText(appointment.description + " in " + appointment.location);
            mBuilder.setAutoCancel(true);
            mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

            Intent resultIntent = new Intent(context, AppointmentActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(AppointmentActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

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

            if (Build.VERSION.SDK_INT >= 26) {
                String channelId = APPOINTMENT_NOTIFICATIONCHANNEL_ID;
                CharSequence channelName = APPOINTMENT_NOTIFICATIONCHANNEL_ID;
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                        importance);
                notificationChannel.enableLights(false);
                notificationChannel.enableVibration(false);
                notificationChannel.setImportance(NotificationManager.IMPORTANCE_LOW);
                mNotificationManager.createNotificationChannel(notificationChannel);
                mBuilder.setChannelId(APPOINTMENT_NOTIFICATIONCHANNEL_ID);
            }
            mNotificationManager.notify(APPOINTMENT_NOTIFICATION_ID, mBuilder.build());

            previousAppointment = mGson.toJson(appointment);
            configUtil.setString("previous_appointment", previousAppointment);
        }
    } else {
        NotificationManager notifManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notifManager.cancel(APPOINTMENT_NOTIFICATION_ID);
    }
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void newHomeworkNotification() {
    Appointment[] newhomework = homeworkDB.getAppointmentsWithHomework();
    ArrayList<Appointment> homeworkList = new ArrayList<>();
    for (Appointment appointment : newhomework) {
        if (homeworkDB.isModified(appointment, true))
            homeworkList.add(appointment);
    }//w  w  w  .  j a  va  2 s. c o  m
    Log.d(TAG, "newHomeworkNotification: Amount of new homework: " + homeworkList.size());
    if (homeworkList.size() > 0) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
        mBuilder.setSmallIcon(R.drawable.ic_new_homework);

        String content = "Je hebt nieuw of aangepast huiswerk voor:";
        for (Appointment appointment : homeworkList) {
            content = content + "\n" + appointment.description
                    + DateUtils.formatDate(appointment.startDate, "' ('dd MMM')'");
        }

        mBuilder.setContentTitle("Nieuw huiswerk");
        mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content));
        mBuilder.setContentText(content);
        mBuilder.setAutoCancel(true);
        mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        mBuilder.setDefaults(Notification.DEFAULT_ALL);

        Intent resultIntent = new Intent(context, HomeworkActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(ScheduleChangeActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= 26) {
            String channelId = NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID;
            CharSequence channelName = NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID;
            int importance = NotificationManager.IMPORTANCE_LOW;
            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                    importance);
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.enableVibration(true);
            notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
            notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 });
            mNotificationManager.createNotificationChannel(notificationChannel);
            mBuilder.setChannelId(NEW_HOMEWORK_NOTIFICATIONCHANNEL_ID);
        }
        mNotificationManager.notify(NEW_HOMEWORK_NOTIFICATION_ID, mBuilder.build());
    }
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

private void nextAppointmentChangedNotification() {
    Appointment[] appointments = scheduleChangeDB.getNotificationAppointments();
    String previousChangedAppointment = configUtil.getString("previous_changed_appointment");
    if (appointments.length > 0) {
        Appointment appointment = appointments[0];
        if (!appointment.startDateString.equals(previousChangedAppointment)) {
            String content;//from   w  ww.ja  v a  2 s .c  o m
            if (appointment.description != null && !appointment.description.equalsIgnoreCase("null")) {
                content = appointment.description;
            } else {
                content = "De les is uitgevallen!";
            }

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setSmallIcon(R.drawable.ic_schedule_change);

            mBuilder.setContentTitle("Let op! De volgende les is gewijzigd!");
            mBuilder.setContentText(content);
            mBuilder.setAutoCancel(true);
            mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
            mBuilder.setDefaults(Notification.DEFAULT_ALL);

            Intent resultIntent = new Intent(context, ScheduleChangeActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(ScheduleChangeActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);

            NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= 26) {
                String channelId = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID;
                CharSequence channelName = NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID;
                int importance = NotificationManager.IMPORTANCE_LOW;
                NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName,
                        importance);
                notificationChannel.enableLights(true);
                notificationChannel.setLightColor(Color.RED);
                notificationChannel.enableVibration(true);
                notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
                notificationChannel.setVibrationPattern(new long[] { 100, 200, 150 });
                mNotificationManager.createNotificationChannel(notificationChannel);
                mBuilder.setChannelId(NEXT_APPOINTMENT_CHANGED_NOTIFICATIONCHANNEL_ID);
            }
            mNotificationManager.notify(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID, mBuilder.build());

            configUtil.setString("previous_changed_appointment", appointment.startDateString);
        }
    } else {
        NotificationManager notifManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notifManager.cancel(NEXT_APPOINTMENT_CHANGED_NOTIFICATION_ID);
    }
}