如何发送图片推送通知(GCM) android



我是推送通知概念的新手。所以我正在学习推送通知。我们如何在推送通知中获得多行文本。

最近我在推送通知中也看到了图片。我们如何在android中获得这种类型的推送通知。请任何人建议我或提供链接。提前谢谢你。

我试过了,但没有收到多行通知。

代码:

 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());

要在通知中显示多个文本,可以使用下面的代码。

对于Jelly Bean和更高级别,您可以使用可扩展的通知。最简单的方法是使用NotificationCompat。BigTextStyle用于通知。使用下面的代码。

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
bigTextStyle.setBigContentTitle(getString(R.string.title));
bigTextStyle.bigText(getString(R.string.long_explanation));
mBuilder.setStyle(bigTextStyle);

不能在推送通知中发送图片。发送推送通知有数据限制。

Android

GCM中的消息大小限制为4kb。

https://developer.android.com/google/gcm/server.html params

你必须在服务器端发送图像的Url,然后在接收推送通知时,在接收端你必须从服务器端获取图像,然后你必须在通知中显示图像。

编辑要在通知中显示大图,请参考

在您的服务器端;在消息体中,您可以发送键值数据。
对于多行文本,使用长通知来显示消息。https://developer.android.com/guide/topics/ui/notifiers/notifications.html
对于图像,您需要从服务中请求url并获取该图像并相应地显示
http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html

最新更新