Big Text Android GCM Notification

I am having trouble getting Android Big Text notifications for the work described here: NotificationCompat.BigTextStyle . Here is the code that I use to display notifications. I know that all data will return correctly, because I can display it on the console and as a traditional text and content header. Am I doing something wrong? Does bigTestStyle also need to be defined elsewhere? I hope one of you has done this before and knows what is missing. Thanks.

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

My code is:

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()); 
+6
source share
1 answer

From the NotificationCompat.BigTextStyle documentation:

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

Your platform may not support widescreen notifications.

EDIT:

On the other hand, maybe 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 changing it to:

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

or:

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

EDIT2:

Cost notification layout for older versions of Android:

 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); } } 
+4
source

Source: https://habr.com/ru/post/944742/


All Articles