简体   繁体   English

如何在推送通知(GCM)Android中发送图像?

[英]how to send images in push notifications (GCM) android?

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. 我们如何在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());

For showing multiple text in notification you can use below code. 要在通知中显示多个文本,可以使用以下代码。

For Jelly Bean and higher you can use an expandable notification. 对于Jelly Bean及更高版本,您可以使用可扩展通知。 The easiest way is to use the NotificationCompat.BigTextStyle for your notification.Use below code. 最简单的方法是对通知使用NotificationCompat.BigTextStyle。使用以下代码。

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. GCM中的邮件大小限制为4 KB。

https://developer.android.com/google/gcm/server.html#params 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. 取而代之的是,您必须在服务器中发送图像的Url,然后在接收到推送通知时在Receiver端从服务器获取图像,然后必须在通知中显示图像。

EDIT For showing large image in notification refer this . 编辑要在通知中显示大图像,请参阅

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 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. 对于图像,您需要从服务中请求一个URL,然后获取该图像并进行相应显示。
http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM