Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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());
like image 903
centree Avatar asked May 10 '13 20:05

centree


People also ask

How do I make my Android notifications bigger?

Create a notification with media controls Apply NotificationCompat. MediaStyle to display media playback controls and track information. Call addAction() up to five times to display up to five separate icon buttons. And call setLargeIcon() to set the album artwork.

How does GCM push notification work?

The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app.

What is Channel ID in Android notification?

ChannelId is a unique String to identify each NotificationChannel and is used in Notification. Builder (line 7) when constructing the Notification object. NotificationChannel settings, except channel name and description text, are immutable after it is submitted to NotificationManager at line 5.


1 Answers

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);
    }
}
like image 73
Eran Avatar answered Oct 24 '22 06:10

Eran