What is the maximum number of characters that can be displayed in Android and iOS push notification?

只谈情不闲聊 提交于 2019-12-20 17:39:53

问题


What is the maximum number of characters that can be displayed in push notification in Android without the text being truncated?

The documentation for iPhone states that the notification payload has to be under 256 bytes in total, but I was unable to find something similar for Android.


回答1:


Android

The message size limit in Firebase Cloud Messaging (FCM) is 4 kbytes. https://firebase.google.com/docs/cloud-messaging/concept-options#notification-messages-with-optional-data-payload

https://firebase.google.com/docs/cloud-messaging/server#choose

The message size limit in GCM is 4 kbytes. (DEPRECATED) https://developer.android.com/google/gcm/server.html#params

The message size limit in C2DM is 1024 bytes. (DEPRECATED) https://developers.google.com/android/c2dm/#limitations


iOS

For regular remote notifications, the maximum size is 4KB (4096 bytes)

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

Since the introduction of iOS 8 has changed to 2 kbytes!

https://forums.aws.amazon.com/ann.jspa?annID=2626

With iOS 8, Apple introduced new features that enable some rich new use cases for mobile push notifications — interactive push notifications, third party widgets, and larger (2 KB) payloads. Today, we are pleased to announce support for the new mobile push capabilities announced with iOS 8. We are publishing a new iOS 8 Sample App that demonstrates how these new features can be implemented with SNS, and have also implemented support for larger 2KB payloads.

in iOS the size limit is 256 bytes




回答2:


As kabuko said there are a lot of variables. But I did testing on a Galaxy S5 and a Nexus 5, with Android 4.4, and got similar results. If you are looking for ballpark figures I got

Title: 16 chars Text: 27 chars Ticker: 300+ chars (I stopped at 300 characters)

NotificationCompat.Builder builder = new     NotificationCompat.Builder(application.getApplicationContext());

Notification n = builder
    .setContentTitle("XXXXXXXXXXWWWWWWWWWW")
    .setContentText("XXXXXXXXXXWWWWWWWWWWXXXXXXXXXX")
    .setTicker("XXXXXXXXXXWWWWWWWWWWXXXXXXXXXXWWWWWWWWWWXXXXXXXXXWWWWWWWWWW...") // cut short for brevity
    .setSmallIcon(R.drawable.ic_launcher)
    .build();



回答3:


C2DM messages are limited in size to 1024 bytes and are intended to inform the device about new data not to transfer it.

Links:

http://www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html http://code.google.com/android/c2dm/




回答4:


Don't assume that just because something works one way in iOS, that's how it works in Android. As Vineet alludes to, in Android's C2DM only deals with data. It does not deal with UI. Adding a notification in the notifications tray is a common thing to do with that push notification, but it's not directly related. As noted in other answers, the message size limit is 1024 bytes.

If you're concerned about how many characters can fit in a notification in the tray however, there is technically no hard limit. For one, Android does not use fixed width fonts (by default) in the tray. A string of 10 characters like "llllllllll" will be a different width than a string of 10 characters like "WWWWWWWWWW". Additionally, you can do custom views in notifications, meaning you can change the font size which would change the number of characters that you can fit.




回答5:


The message size limit is 1024 bytes.

http://code.google.com/android/c2dm/index.html#limitations




回答6:


GCM (Google Cloud Messaging)- 4kb

ref : https://developers.google.com/cloud-messaging/server#choose

FCM (firebase cloud messaging)- 4kb

ref: https://firebase.google.com/docs/cloud-messaging/server#choose



来源:https://stackoverflow.com/questions/9487223/what-is-the-maximum-number-of-characters-that-can-be-displayed-in-android-and-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!