问题描述
我有一个Android应用程序,它支持7个国家(本地化和国际化)。该应用程序的功能和语言已改变基于设备的语言环境。我需要实现这个应用程序的GCM推送通知。需求:1.是否可以发送推送通知的7种不同的语言,单GCM账户。2,有没有什么办法来显示其设备本地语言的推送通知。谢谢Ganesh神。
I have a single android application, which supports for 7 countries(Localization and Internationalization). The application functionality and language changed based on the device locale.I need to implement the GCM push notifications for this application.Requirement:1. Is it possible to send the push notification in 7 different languages with single GCM account.2. Is there any way to display the push notification in their device local language.ThanksGanesh.
推荐答案
您可以乘坐由维他命C建议的方法,或实现自己的推送通知类似于苹果有一些:
You can either take the approach suggested by Ascorbin, or implement something similar to what Apple have in their push notifications:
您的服务器可以发送GCM消息的参数是一个关键的消息。 YOUT Android应用程序必须包含应在每7种语言(使用strings.xml中的多个副本)来显示它的每个可能的密钥字符串。然后在你的应用程序中的GCM reciever将得到来自服务器的密钥,并获得相匹配(它会自动获得相匹配的设备的语言环境的字符串)资源字符串。这样,您就不必担心本地化的服务器。 这种方法的缺点是,所有的邮件都必须pdefined在你的应用程序$ P $。
Your server can send a GCM message with a parameter that is a key to a message. Yout Android App will have to contain for each possible key the strings that should be displayed for it in each of the 7 languages (using multiple copies of strings.xml). Then the GCM reciever in your app will get the key from the server and get the resource string that matches it (it will automatically get the string that matched the locale of the device). This way you don't have to worry about localization in your server. The downside of this approach is that all your messages have to be predefined in your app.
您也可以参数添加到像苹果做信息键。例如,服务器会发送一个关键=NEW_MAIL_FROM和参数1 =约翰。该应用程序发现该键字符串资源(让我们假设的英语语言环境中的设备) - 你必须从{0}的消息 - 和替换约翰·帕拉姆,显示消息你有一个消息约翰。的设备与differennt区域会显示一条消息,在不同的语言。
You can also add parameters to the message key like Apple do.For example, the server sends a key = "NEW_MAIL_FROM" and param1 = "John". The app finds a string resource for that key (lets assume the device used English locale) - "You have a message from {0}" - and replaces the param with John, displaying the message "You have a message from John". A device with a differennt locale will show a message in a different language.
这篇关于Android的GCM推送通知的本地化应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!