Reputation: 2306
I am new to push notifications concept. So i am learning about push notifications. How we get multi-line text in push notifications.
Recently i saw images in push notifications too. how we get that type of push notifications in android. Please any one suggest me or provide links. Thank you in advance.
I tried but not getting multi line notification. This is not working for older versions .
Code:
PendingIntent p= PendingIntent.getActivity(context, 3456, in, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder b=new NotificationCompat.Builder(context);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.reload_logo)
.setTicker("Post Paid bill")
.setContentTitle("Reload.in")
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
//.setContentText("Rs.has to be paidjhgfhdjgf dhfhh hfdufgjhbj fhgjfg bfdjgjfg jfjb ndjfd d vdgfvhdgf")
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
.setContentIntent(p)
.setContentInfo("Info")
.setContentText(message).build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, b.build());
Upvotes: 0
Views: 7346
Reputation: 12861
For showing multiple text in notification you can use below code.
For Jelly Bean and higher you can use an expandable notification. The easiest way is to use the NotificationCompat.BigTextStyle for your notification.Use below code.
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(getString(R.string.title));
bigTextStyle.bigText(getString(R.string.long_explanation));
mBuilder.setStyle(bigTextStyle);
You can not send images in Push notifications. There is data limit you can send in push notification.
Android
The message size limit in GCM is 4 kbytes.
https://developer.android.com/google/gcm/server.html#params
Instead of that you have to send Url of image in server then on Receiver side at time of receiving push notification you have fetch image from server and then you have to display image in notification.
EDIT For showing large image in notification refer this.
Upvotes: 2
Reputation: 1893
On your server side; In the message body you can send key value data.
For multiline text use long notification to show the message. https://developer.android.com/guide/topics/ui/notifiers/notifications.html
For image you need to ask for a url from service and fetch that image and show accordingly.
http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html
Upvotes: 0