Example usage for android.app Notification VISIBILITY_PUBLIC

List of usage examples for android.app Notification VISIBILITY_PUBLIC

Introduction

In this page you can find the example usage for android.app Notification VISIBILITY_PUBLIC.

Prototype

int VISIBILITY_PUBLIC

To view the source code for android.app Notification VISIBILITY_PUBLIC.

Click Source Link

Document

Notification visibility: Show this notification in its entirety on all lockscreens.

Usage

From source file:com.techmighty.baseplayer.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap artwork;/*from   w  ww. ja  v  a2 s  .  c  o  m*/
    artwork = ImageLoader.getInstance().loadImageSync(BasePlayerUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent)
            .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION));

    if (BasePlayerUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (BasePlayerUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && BasePlayerUtils.isLollipop())
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    Notification n = builder.build();

    if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) {
        addXTrackSelector(n);
    }

    return n;
}

From source file:com.devalladolid.musictoday.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap artwork;/*from w w  w  .  j a  v  a 2  s .  co  m*/
    artwork = ImageLoader.getInstance().loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent)
            .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION));

    if (TimberUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (TimberUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && TimberUtils.isLollipop())
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    Notification n = builder.build();

    if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) {
        addXTrackSelector(n);
    }

    return n;
}

From source file:com.musiqueplayer.playlistequalizerandroidwear.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap artwork;/*from  w  w w  . j a v  a2 s. co  m*/
    artwork = ImageLoader.getInstance().loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.icons);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent)
            .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION));

    if (TimberUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (TimberUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && TimberUtils.isLollipop())
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    Notification n = builder.build();

    if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) {
        addXTrackSelector(n);
    }

    return n;
}

From source file:com.naman14.timber.musicplayer.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //TODO: Replace below Image download using Picasso
    Bitmap artwork;/*from   www.ja v a2s  . com*/
    artwork = ImageLoader.getInstance().loadImageSync(TimberUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent)
            .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION));

    if (TimberUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (TimberUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && TimberUtils.isLollipop()) {
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    }
    Notification n = builder.build();

    //        if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) {
    //            addXTrackSelector(n);
    //        }

    return n;
}

From source file:com.bluros.music.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_white_36dp;

    Intent nowPlayingIntent = NavigationUtils.getNowPlayingIntent(this);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    Bitmap artwork;// w  w  w.j  a  v a2 s  .  c  o  m
    artwork = ImageLoader.getInstance().loadImageSync(MusicUtils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_empty_music2);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    android.support.v4.app.NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork).setContentIntent(clickIntent)
            .setContentTitle(getTrackName()).setContentText(text).setWhen(mNotificationPostTime)
            .addAction(R.drawable.ic_skip_previous_white_36dp, "", retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, "", retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_skip_next_white_36dp, "", retrievePlaybackAction(NEXT_ACTION));

    if (MusicUtils.isJellyBeanMR1()) {
        builder.setShowWhen(false);
    }
    if (MusicUtils.isLollipop()) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle()
                .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2, 3);
        builder.setStyle(style);
    }
    if (artwork != null && MusicUtils.isLollipop())
        builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));
    Notification n = builder.build();

    if (PreferencesUtility.getInstance(this).getXPosedTrackselectorEnabled()) {
        addXTrackSelector(n);
    }

    return n;
}

From source file:com.koma.music.service.MusicService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.ic_pause_black_36dp : R.drawable.ic_play_arrow_black_36dp;
    int playButtonTitleResId = isPlaying ? R.string.notification_pause : R.string.notification_play;

    Notification.MediaStyle style = new Notification.MediaStyle().setMediaSession(mSession.getSessionToken())
            .setShowActionsInCompactView(0, 1, 2);

    Intent nowPlayingIntent = new Intent("com.koma.music.notification.AUDIO_PLAYER")
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, 0);

    Bitmap artwork;/*  ww w . jav  a2 s . c o  m*/
    artwork = ImageLoader.getInstance().loadImageSync(Utils.getAlbumArtUri(getAlbumId()).toString());

    if (artwork == null) {
        artwork = ImageLoader.getInstance().loadImageSync("drawable://" + R.drawable.ic_album);
    }

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }

    Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_notification)
            .setLargeIcon(artwork).setContentIntent(clickIntent).setContentTitle(getTrackName())
            .setContentText(text).setWhen(mNotificationPostTime).setShowWhen(false).setStyle(style)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .addAction(R.drawable.ic_previous_notification, getString(R.string.notification_prev),
                    retrievePlaybackAction(MusicServiceConstants.PREVIOUS_ACTION))
            .addAction(playButtonResId, getString(playButtonTitleResId),
                    retrievePlaybackAction(MusicServiceConstants.TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.ic_next_notification, getString(R.string.notification_next),
                    retrievePlaybackAction(MusicServiceConstants.NEXT_ACTION));

    if (artwork != null) {
        // builder.setColor(Palette.from(artwork).generate().getVibrantColor(Color.parseColor("#403f4d")));

        builder.setColor(
                Palette.from(artwork).generate().getMutedColor(getResources().getColor(R.color.colorPrimary)));
    }
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);

    return builder.build();
}

From source file:com.cyanogenmod.eleven.MusicPlaybackService.java

private Notification buildNotification() {
    final String albumName = getAlbumName();
    final String artistName = getArtistName();
    final boolean isPlaying = isPlaying();
    String text = TextUtils.isEmpty(albumName) ? artistName : artistName + " - " + albumName;

    int playButtonResId = isPlaying ? R.drawable.btn_playback_pause : R.drawable.btn_playback_play;
    int playButtonTitleResId = isPlaying ? R.string.accessibility_pause : R.string.accessibility_play;

    android.support.v7.app.NotificationCompat.MediaStyle style = new android.support.v7.app.NotificationCompat.MediaStyle()
            .setMediaSession(mSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2);

    Intent nowPlayingIntent = new Intent("com.cyanogenmod.eleven.AUDIO_PLAYER")
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, 0);
    BitmapWithColors artwork = getAlbumArt(false);

    if (mNotificationPostTime == 0) {
        mNotificationPostTime = System.currentTimeMillis();
    }//from  w  w w .  ja v a2  s  .  co  m

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_notification).setLargeIcon(artwork.getBitmap())
            .setContentIntent(clickIntent).setContentTitle(getTrackName()).setContentText(text)
            .setWhen(mNotificationPostTime).setShowWhen(false).setStyle(style)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .addAction(R.drawable.btn_playback_previous, getString(R.string.accessibility_prev),
                    retrievePlaybackAction(PREVIOUS_ACTION))
            .addAction(playButtonResId, getString(playButtonTitleResId),
                    retrievePlaybackAction(TOGGLEPAUSE_ACTION))
            .addAction(R.drawable.btn_playback_next, getString(R.string.accessibility_next),
                    retrievePlaybackAction(NEXT_ACTION));

    builder.setColor(artwork.getVibrantDarkColor());

    return builder.build();
}

From source file:mp.teardrop.PlaybackService.java

/**
 * Create a song notification. Call through the NotificationManager to
 * display it./*from w  w w  . j  a  v a2s .c  o  m*/
 *
 * @param song The Song to display information about.
 * @param state The state. Determines whether to show paused or playing icon.
 */
public Notification createNotification(Song song, int state) {
    boolean playing = (state & FLAG_PLAYING) != 0;

    RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
    RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);

    Bitmap cover = song.getCover(this);
    if (cover == null) {
        views.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
        expanded.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
    } else {
        views.setImageViewBitmap(R.id.cover, cover);
        expanded.setImageViewBitmap(R.id.cover, cover);
    }

    int playButton = getPlayButtonResource(playing);

    views.setImageViewResource(R.id.play_pause, playButton);
    expanded.setImageViewResource(R.id.play_pause, playButton);

    ComponentName service = new ComponentName(this, PlaybackService.class);

    Intent previous = new Intent(PlaybackService.ACTION_PREVIOUS_SONG);
    previous.setComponent(service);
    expanded.setOnClickPendingIntent(R.id.previous, PendingIntent.getService(this, 0, previous, 0));

    Intent playPause = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK_NOTIFICATION);
    playPause.setComponent(service);
    views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));
    expanded.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));

    Intent next = new Intent(PlaybackService.ACTION_NEXT_SONG);
    next.setComponent(service);
    views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
    expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));

    Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION);
    close.setComponent(service);
    views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
    expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));

    views.setTextViewText(R.id.title, song.title);
    views.setTextViewText(R.id.artist, song.artist);
    expanded.setTextViewText(R.id.title, song.title);
    expanded.setTextViewText(R.id.album, song.album);
    expanded.setTextViewText(R.id.artist, song.artist);

    Notification notification = new Notification();
    notification.contentView = views;
    notification.icon = R.drawable.status_icon;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.contentIntent = mNotificationAction;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // expanded view is available since 4.1
        notification.bigContentView = expanded;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    //        if(mNotificationNag) {
    //            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    //                notification.priority = Notification.PRIORITY_MAX;
    //                notification.vibrate = new long[0]; // needed to get headsup
    //            } else {
    //                notification.tickerText = song.title + " - " + song.artist;
    //            }
    //        }

    return notification;
}

From source file:org.restcomm.android.sdk.RCDevice.java

void onNotificationCall(RCConnection connection, HashMap<String, String> customHeaders) {
    String peerSipUri = connection.getPeer().replaceAll("^<", "").replaceAll(">$", "");
    String peerUsername = peerSipUri.replaceAll(".*?sip:", "").replaceAll("@.*$", "");

    String text;//from w  w w.  ja v a 2s . c  o  m
    if (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO) {
        text = "Incoming video call";
    } else {
        text = "Incoming audio call";
    }

    // Intent to open the call activity (for when tapping on the general notification area)
    Intent serviceIntentDefault = new Intent(ACTION_NOTIFICATION_CALL_DEFAULT, null, getApplicationContext(),
            RCDevice.class);
    serviceIntentDefault.putExtra(RCDevice.EXTRA_DID, peerSipUri);
    serviceIntentDefault.putExtra(RCDevice.EXTRA_VIDEO_ENABLED,
            (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO));
    if (customHeaders != null) {
        serviceIntentDefault.putExtra(RCDevice.EXTRA_CUSTOM_HEADERS, customHeaders);
    }

    // Intent to directly answer the call as video (using separate actions instead of EXTRAs, cause with EXTRAs the intents aren't actually differentiated: see PendingIntent reference documentation)
    Intent serviceIntentVideo = new Intent(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO, null, getApplicationContext(),
            RCDevice.class);
    serviceIntentVideo.putExtras(serviceIntentDefault);

    // Intent to directly answer the call as audio
    Intent serviceIntentAudio = new Intent(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO, null, getApplicationContext(),
            RCDevice.class);
    serviceIntentAudio.putExtras(serviceIntentDefault);

    // Intent to decline the call without opening the App Activity
    Intent serviceIntentDecline = new Intent(ACTION_NOTIFICATION_CALL_DECLINE, null, getApplicationContext(),
            RCDevice.class);
    serviceIntentDecline.putExtras(serviceIntentDefault);

    // Intent for when the user deletes notification
    Intent serviceIntentDelete = new Intent(ACTION_NOTIFICATION_CALL_DELETE, null, getApplicationContext(),
            RCDevice.class);
    serviceIntentDelete.putExtras(serviceIntentDefault);

    NotificationCompat.Builder builder = getNotificationBuilder(true);

    builder.setSmallIcon(R.drawable.ic_call_24dp).setContentTitle(peerUsername).setContentText(text)
            // Need this to show up as Heads-up Notification
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true) // cancel notification when user acts on it (Important: only applies to default notification area, not additional actions)
            .setVibrate(notificationVibrationPattern).setVisibility(Notification.VISIBILITY_PUBLIC)
            .setLights(notificationColor, notificationColorPattern[0], notificationColorPattern[1]);

    if (audioManager != null)
        builder = builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/"
                + audioManager.getResourceIdForKey(ParameterKeys.RESOURCE_SOUND_RINGING)));
    if (callIntent != null) {
        builder = builder
                .addAction(R.drawable.ic_videocam_24dp, "Video",
                        PendingIntent.getService(getApplicationContext(), 0, serviceIntentVideo,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                .addAction(R.drawable.ic_call_24dp, "Audio",
                        PendingIntent.getService(getApplicationContext(), 0, serviceIntentAudio,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                .addAction(R.drawable.ic_call_end_24dp, "Hang Up",
                        PendingIntent.getService(getApplicationContext(), 0, serviceIntentDecline,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                .setContentIntent(PendingIntent.getService(getApplicationContext(), 0, serviceIntentDefault,
                        PendingIntent.FLAG_UPDATE_CURRENT))
                .setDeleteIntent(PendingIntent.getService(getApplicationContext(), 0, serviceIntentDelete,
                        PendingIntent.FLAG_UPDATE_CURRENT));

    } else {
        //we dont want to show the notification to primary channel
        builder = builder.setContentIntent(PendingIntent.getService(getApplicationContext(), 0,
                serviceIntentDefault, PendingIntent.FLAG_UPDATE_CURRENT));
    }

    Notification notification = builder.build();
    // Add FLAG_INSISTENT so that the notification rings repeatedly (FLAG_INSISTENT is not exposed via builder, let's add manually)
    notification.flags = notification.flags | Notification.FLAG_INSISTENT;

    boolean notificationIdExists = true;
    Integer activeNotificationId = callNotifications.get(peerUsername);

    if (activeNotificationId == null) {
        activeNotificationId = notificationId;
        notificationIdExists = false;
    }

    //show to the user notification and start foreground
    startForeground(notificationId, notification);

    if (!notificationIdExists) {
        // We used a new notification id, so we need to update call notifications
        callNotifications.put(peerUsername, notificationId);
        notificationId++;
    }

    activeCallNotification = true;
}

From source file:org.restcomm.android.sdk.RCDevice.java

/**
 * Method returns the Notification builder
 * For Oreo devices we can have channels with HIGH and LOW importance.
 * If highImportance is true builder will be created with HIGH priority
 * For pre Oreo devices builder without channel will be returned
 * @param highImportance true if we need HIGH channel, false if we need LOW
 * @return//  w  w w  . j  ava2  s  . c  o m
 */
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;
}