centree
centree

Reputation: 2439

Notification Big Text Android GCM

I'm having trouble getting Android's Big Text notifications to work as documented here: NotificationCompat.BigTextStyle. Here's the code I'm using to display notifications. I know all the data is coming back correctly because I can get it to display on the console and as the traditional content text and title. Am I doing something wrong? Do I need to define bigTestStyle somewhere else as well? Hopefully one of you has done this before and knows what could be missing. Thanks.

As you can see the big text message text is not displaying

My code:

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.bigText(extras.getString("message"));
    NotificationCompat.Builder bigTextNotification = new NotificationCompat.Builder(context)
            .setContentTitle("My App")
            .setContentIntent(pendingIntent)
            .setContentText("Message:")
            .setSound(soundUri)
            .setTicker(extras.getString("message"))
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.splash)
            .setAutoCancel(true)
            .setVibrate(new long[] { 0, 100, 200, 300 })
            .setStyle(bigTextStyle);
    final int notificationId = (int) (System.currentTimeMillis() / 1000L);
    NotificationManager thisone = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    thisone.notify(notificationId, bigTextNotification.build());

Upvotes: 6

Views: 10174

Answers (1)

Eran
Eran

Reputation: 393841

From NotificationCompat.BigTextStyle documentation :

Helper class for generating large-format notifications that include a lot of text. If the platform does not provide large-format notifications, this method has no effect. The user will always see the normal notification view.

Perhaps your platform doesn't support large-format notifications.

EDIT :

On the other hand, it's possible your problem is here :

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.bigText(extras.getString("message"));

You are not using the return value of bigText.

Try to change it to :

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle  = bigTextStyle.bigText(extras.getString("message"));

or to :

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(extras.getString("message"));

EDIT2 :

Costom Notification Layout for older Android versions :

protected void onMessage(Context context, Intent intent) {
    // Extract the payload from the message
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String message = (String) extras.get("message");
        String title = (String) extras.get("title");                

        // add a notification to status bar
        NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Intent myIntent = new Intent(this,MyActivity.class);
        Notification notification = new Notification(R.drawable.notification_image, title, System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
        contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
        contentView.setTextViewText(R.id.title, title);
        contentView.setTextViewText(R.id.text, message);
        notification.contentView = contentView;
        notification.contentIntent = PendingIntent.getActivity(this.getBaseContext(), 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        mManager.notify(0, notification);
        PowerManager pm = (PowerManager) 
        context.getSystemService(Context.POWER_SERVICE);
        WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
        wl.acquire(15000);
    }
}

Upvotes: 4

Related Questions