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:org.runnerup.util.NotificationCompat.java

public static void setVisibility(Builder builder) {
    if (Build.VERSION.SDK_INT >= 21) {
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }//w  w  w  .  ja va  2 s .co m
}

From source file:MainActivity.java

@Deprecated
public void showNotification(View view) {
    Intent activityIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);

    Notification notification;//from  w  w w.j  a v  a2  s  . c o  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_previous), "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_pause), "Pause",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(
                        Icon.createWithResource(this, android.R.drawable.ic_media_next), "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    } else {
        notification = new Notification.Builder(this).setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(R.mipmap.ic_launcher)
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_previous, "Previous",
                        pendingIntent).build())
                .addAction(new Notification.Action.Builder(android.R.drawable.ic_media_pause, "Pause",
                        pendingIntent).build())
                .addAction(
                        new Notification.Action.Builder(android.R.drawable.ic_media_next, "Next", pendingIntent)
                                .build())
                .setContentTitle("Music").setContentText("Now playing...")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setStyle(new Notification.MediaStyle()
                        //.setMediaSession(mMediaSession.getSessionToken())
                        .setShowActionsInCompactView(1))
                .build();
    }
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:hmatalonga.greenhub.util.Notifier.java

public static void startStatusBar(final Context context) {
    if (isStatusBarShown)
        return;/*w  ww  .j  a  v  a  2 s .  co m*/

    // At this moment Inspector still doesn't have a current level assigned
    DataEstimator estimator = new DataEstimator();
    estimator.getCurrentStatus(context);

    int now = Battery.getBatteryCurrentNow(context);
    int level = estimator.getLevel();
    String title = "Now: " + now + " mA";
    String text = "GreenHub is running";

    sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text)
            .setAutoCancel(false).setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (level < 100) {
        sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}

From source file:org.linphone.compatibility.ApiTwentyOnePlus.java

public static Notification createInCallNotification(Context context, String title, String msg, int iconID,
        Bitmap contactIcon, String contactName, PendingIntent intent) {

    Notification notif = new NotificationCompat.Builder(context).setContentTitle(contactName)
            .setContentText(msg).setSmallIcon(iconID).setAutoCancel(false).setContentIntent(intent)
            .setLargeIcon(contactIcon).setCategory(Notification.CATEGORY_CALL)
            .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_HIGH).build();

    return notif;
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void startStatusBar(final Context context) {
    if (isStatusBarShown)
        return;//from w  ww.  ja v a 2  s.  c om

    // At this moment Inspector still doesn't have a current level assigned
    DataEstimator estimator = new DataEstimator();
    estimator.getCurrentStatus(context);

    int now = Battery.getBatteryCurrentNow(context);
    int level = estimator.getLevel();
    String title = context.getString(R.string.now) + ": " + now + " mA";
    String text = context.getString(R.string.notif_batteryhub_running);

    sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text)
            .setAutoCancel(false).setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (level < 100) {
        sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}

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  ww  w.ja  va2s.  c o m*/
}

From source file:com.davidmiguel.gobees.utils.NotificationsHelper.java

@RequiresApi(Build.VERSION_CODES.O)
private void createMonitoringChannel() {
    NotificationChannel channel = new NotificationChannel(MONITORING_CHANNEL,
            getString(R.string.not_channel_monitoring), NotificationManager.IMPORTANCE_LOW);
    channel.setDescription(getString(R.string.not_channel_monitoring_desc));
    channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
    channel.setShowBadge(false);//from w ww. jav a2  s. co m
    channel.enableLights(false);
    getManager().createNotificationChannel(channel);
}

From source file:github.daneren2005.dsub.util.Notifications.java

public static void showPlayingNotification(final Context context, final DownloadService downloadService,
        final Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());

    final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (playing) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }//from  w ww  . ja  va2 s. c o m
    boolean remote = downloadService.isRemoteEnabled();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, true, playing, remote);
        notification.bigContentView = expandedContentView;
        notification.priority = Notification.PRIORITY_HIGH;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, false, playing, remote);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
    notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    playShowing = true;
    if (downloadForeground && downloadShowing) {
        downloadForeground = false;
        handler.post(new Runnable() {
            @Override
            public void run() {
                downloadService.stopForeground(true);
                showDownloadingNotification(context, downloadService, handler,
                        downloadService.getCurrentDownloading(),
                        downloadService.getBackgroundDownloads().size());
                downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                if (playing) {
                    downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
                } else {
                    playShowing = false;
                    persistentPlayingShowing = true;
                    NotificationManager notificationManager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    downloadService.stopForeground(false);
                    notificationManager.notify(NOTIFICATION_ID_PLAYING, notification);
                }
            }
        });
    }

    // Update widget
    DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}

From source file:com.sxt.chat.utils.NotificationHelper.java

/**
 * ?//from   w ww  . jav a2  s  . c  om
 * <p>
 * note : notify() ? ???,?? so, Create?
 */
public NotificationHelper(Context ctx) {
    super(ctx);
    context = ctx;
    soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notify_message);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AudioAttributes att = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
        NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL, "Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        channel.setLightColor(Color.YELLOW);
        channel.setShowBadge(true);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(channel);

        NotificationChannel chanCustom = new NotificationChannel(CUSTOM_NOTIFY_CHANNEL, "Custom Layout Channel",
                NotificationManager.IMPORTANCE_HIGH);
        channel.setSound(soundUri, att);
        chanCustom.setLightColor(Color.RED);
        chanCustom.setShowBadge(true);
        chanCustom.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        getManager().createNotificationChannel(chanCustom);
    }
}

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);/*from w w w.  ja  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());
}