|
http://blog.csdn.net/lee4755026/article/details/9699713 2013 最近研究了一下Android推送,在網(wǎng)上搜到了很多種方式,覺得IBM的MQTT協(xié)議這種方式還是挺不錯的。
下面介紹一下搭建過程:
需要準(zhǔn)備的工具如下:
(1)、下載Mosquitto(MQTT的代理,也可以用IBM的ISMB)
http:///download/
我下載的是mosquitto-1.1.2-install-win32.exe,根據(jù)自己的需要下載,不安裝這個推送不了消息。
(2)、下載AndroidPushNotificationsDemo
https://github.com/tokudu/Androi ... /archive/master.zip
(3)、下載PhpMQTTClient
https://github.com/tokudu/PhpMQTTClient/archive/master.zip
將PHPMQTTClient部署到PHP服務(wù)器上,運行,打開mosquitto安裝目錄的mosquitto.exe
將以下AndroidPushNotificationsDemo的代碼根據(jù)自己的情況修改。
- public class PushService extends Service
- {
- // this is the log tag
- public static final String TAG = "DemoPushService";
-
- // the IP address, where your MQTT broker is running.
- //修改成自己的服務(wù)器地址
- private static final String MQTT_HOST =
- // "209.124.50.174"
- // "192.168.12.19"
- "10.0.2.2"
- ;
- // the port at which the broker is running.
- private static int MQTT_BROKER_PORT_NUM = 1883;
- // Let's not use the MQTT persistence.
- private static MqttPersistence MQTT_PERSISTENCE = null;
輸入Device target ID ,內(nèi)容,點擊按鈕,OK!
 
PS:
原來其實是不需要那個PHP的,直接用mosquitto_pub.exe就可以測試了,運行客戶端程序,在命令窗口中使用Mosquitto_pub.exe -q [Qos級別] -t [主題] -m [發(fā)布的內(nèi)容] 進行測試。這個android客戶端例子中訂閱的topic是“tokudu/你的deviceID”。
一些別的資料:
http://www.cnblogs.com/yjl49/archive/2012/05/17/2506819.html
|