user1940676
user1940676

Reputation: 4448

Can't display more text in a notification

I am trying to show a notification in the title bar with a long text.

    PendingIntent contentIntent = PendingIntent.getActivity(context,
            NOTIFICATION_ID, notificationIntent,
            PendingIntent.FLAG_ONE_SHOT);
    NotificationManager nm = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
    builder.setContentIntent(contentIntent)
            .setSmallIcon(R.drawable.icon_push).setTicker(alert)
            .setContentTitle(title).setContentText(alert)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.setStyle(new NotificationCompat.BigTextStyle()
                .bigText(title));
    }
    Notification n = builder.build();
    nm.notify(id, n);

But the builder.setStyle(new NotificationCompat.BigTextStyle() .bigText(title));

The setStyle seems to do nothing, I am testing it on android 4.1

Upvotes: 4

Views: 2478

Answers (3)

Yao Xu
Yao Xu

Reputation: 1

use:Notification.Builder(context).setFullScreenIntent(pendingIntent, true), manual to make the notification full screen

Upvotes: 0

artemiygrn
artemiygrn

Reputation: 1036

You should remove this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {

because this is compatible, it's automatically set right.

And this is 100% working code:

        NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            this);
    builder.setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("titletitletitletitletitletitletitletitletitletitletitletitle").setContentText("contentcontentcontentcontentcontentcontentcontent")
            .setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText("bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig"));

    Notification notification = builder.build();
    notificationManager.notify(1, notification);

Upvotes: 7

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

If your variable names are correct and your variable named title is only the title then your problem is that you are using bigText(title) instead of bigText(aReallyBigText);

Upvotes: 1

Related Questions