简体   繁体   English

如何发送通知?

[英]How can I send a notification?

I am developing an Android App that communicates with a server. 我正在开发与服务器通信的Android应用程序。 How can I send a notification from my server to my Android App without the use of C2DM? 如何在不使用C2DM的情况下从服务器向Android应用发送通知? Are Sockets a good solution? 套接字是一个好的解决方案吗? What are other alternatives? 还有哪些其他选择?

I'd suggest you to develop a webservice preferably with JSON which is easy to handle. 我建议您最好使用易于处理的JSON开发一个Web服务。 This server client architecture will hellp you to send and receive any kind of data (ranges from raw text to images or even video) 这种服务器客户端体系结构会欺骗您发送和接收任何类型的数据(范围从原始文本到图像甚至是视频)

Check out C# webservices. 查看C#Web服务。 That are very easy to start than the PHP services IMHO. 比起PHP服务恕我直言,这非常容易启动。

Depends on what you want to do. 取决于您要做什么。

have you thought on how does the server identifies the client to send the message ? 您是否考虑过服务器如何识别客户端以发送消息? In this case the android phone ? 在这种情况下android手机?

With http you would need the client to "request" this notification. 使用http,您需要客户端“请求”此通知。

The closest thing to an actual notification would be to have a socket connection, which the client would connect to the server. 与实际通知最接近的是建立套接字连接,客户端将其连接到服务器。 But then would require an existent connection between the two. 但这将要求两者之间存在连接。 If this is ok for what you are doing, then go ahead if you really want to avoid C2DM. 如果您的工作没问题,那么如果您真的想避免使用C2DM,请继续进行。

But, using C2DM allows your server to send notification to devices without a need for a request or direct connection from the client. 但是,使用C2DM可使您的服务器将通知发送到设备,而无需来自客户端的请求或直接连接。 The only thing you need to do is pass the identification of the device to your third-party server given when you authenticate with google's C2DM. 您唯一需要做的就是将设备的标识传递给您在通过Google的C2DM进行身份验证时提供的第三方服务器。 After that, you just push notification data to C2DM and google delivers the notification for you. 之后,您只需将通知数据推送到C2DM,Google就会为您发送通知。

I've used MQTT for providing push notifications on Android and it's proved to be a good, reliable, low power solution. 我已经使用MQTT在Android上提供推送通知,并且事实证明这是一个很好,可靠的低功耗解决方案。

Some links to support my case / get you started: 一些支持我的案例的链接/帮助您入门:

http://mqtt.org/ http://mqtt.org/

Power Profiling: MQTT on Android 功耗分析:Android上的MQTT

Basic Steps for Using MQTT in android 在Android中使用MQTT的基本步骤

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

相关问题 如何使用Java中的自定义字段发送推送通知? - How can I send a push notification with custom fields from Java? 如何通过 Android 发送 Flash(通知)短信? - How can send Flash (Notification) SMS by Android? 我如何只知道 Button OnClickListener 中的用户 ID 就可以向特定用户发送推送通知? Firebase - How can i send push notification to specific users just knowing the userID inside Button OnClickListener? Firebase 如何在特定时间从 spring api 向移动应用程序发送通知,例如提醒? - How can i send notification to mobile app from spring api on specific time like a reminder? 发送 Firebase 通知 (FCM) 时如何唤醒设备 - how I can wake up the device when send Firebase notification (FCM) 我的应用未运行时,如何发送类似Facebook的推送通知(背景/前景) - how can i send push notification like facebook while my app is not running(background/foreground) 如何使用 Firebase 中的用户令牌向特定用户发送通知? - How can I send notification to specific User using the user's token in Firebase? 如何向用户发送通知 - How to send notification to the user 消息传递服务器如何使目标客户端独立化并发送推送通知 - How can a messaging server indetify target client and send push notification JavaFX Webview可以发送通知吗? - Can JavaFX Webview send a notification?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM