我最近一直在學習Android開發,並試圖製作一個使用Google Cloud Messaging的示例應用程序。我的目標是製作一個簡單的應用程序,可以從服務器接收推送通知。通過註冊我的設備,我已經讓應用程序的客戶端工作。現在我正在嘗試創建服務器端。但是,我完全沒有在服務器端建立服務器或編程的經驗。所以我希望有人能指引我正確的方向,這樣我就可以有一臺服務器發送推送通知。我一直在關注this link的教程,但我堅持服務器實現。如果有人能指引我朝着正確的方向,我將不勝感激。謝謝!爲Google Cloud Messaging設置服務器端
6
A
回答
1
如果您使用過PHP,您應該熟悉xampp或類似軟件。
如果沒有,你需要做的就是下載並安裝它,啓動服務和瀏覽器訪問:
http://localhost/xampp
,以測試它是否正確安裝。
如果你能看到XAMPP的頁面,您可以開始運行的XAMPP/htdocs中的腳本php和這樣運行了他們:
http://localhost/yourscript.php
嘗試一個簡單的Hello World:
<?php
echo 'hello world';
?>
之後,你應準備好開始以下this tutorial或任何教程在谷歌只是打字gcm php tutorial
我發現,PHP是我最簡單的方式來c爲GCM配置服務器端,希望您覺得它有用...
6
實際上使用Tomcat或AppEngine更容易。 See this tutorial in how to setup your GCM Server.
您需要的設備登記ID來要發送郵件在服務器端,你需要你的API密鑰,這是一個JSP示例:
http://yourdomain.com:8080/sendMessage.jsp?registrationID=kSADAS3242&messageToSend=Hello
String value = request.request.getParameter("messageToSend");
String registrationId = request.getParameter("registrationID");
Sender sender = new Sender("YOUR API KEY");
Message message = new Message.Builder().addData("FLAG","SERVE").addData("MSG", value).build();
Result result = sender.send(message, registrationId, 5);
在您客戶端設備應該期望:
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Got a message from Google Cloud Messaging !!");
String tag = intent.getExtras().getString("FLAG");
String message = intent.getExtras().getString("MSG");
Log.i(TAG, tag + " : " + message);
}
這應打印 「服務:您好」
相關問題
- 1. Google Cloud Messaging - 服務器端
- 2. Google Cloud Messaging服務器端
- 3. 爲Google Cloud Messaging設置服務器端和客戶端
- 4. Google Cloud Messaging服務器的IP地址
- 5. Google Cloud messaging - 示例服務器
- 6. 如何爲Android設置Google Cloud Messaging?
- 7. C#中Google Cloud Messaging服務器端代碼
- 8. Google-Cloud-Messaging服務的可靠性
- 9. Google Cloud Messaging
- 10. Google Cloud Messaging(GCM)
- 11. Google Clound Messaging服務器C#
- 12. Mule ESB Google Cloud Messaging
- 13. Google Cloud Messaging示例
- 14. Google Cloud Messaging Smack Library
- 15. Android Google - Cloud Messaging Report
- 16. 服務器如何找到GCM(Google Cloud Messaging)註冊ID
- 17. 帶有Node.js的Google Cloud Messaging XMPP服務器
- 18. 設備和GCM服務器之間的Google Cloud Messaging通道有多安全?
- 19. 爲Google Cloud端點設置指標
- 20. SignalR Vs Google Cloud messaging Vs Parse
- 21. Google Cloud Messaging註冊AUTHENTICATION_FAILED
- 22. 何時註冊Google Cloud Messaging?
- 23. PhoneGap Google Cloud Messaging Android問題
- 24. GCM問題(Google Cloud Messaging)
- 25. 如何下載Google Cloud Messaging
- 26. Google Cloud Messaging - 存儲限制
- 27. Pushwoosh - Google Cloud Messaging - 傳輸
- 28. Google Cloud Messaging - 發送消息
- 29. Google Cloud Messaging連接問題
- 30. 活動監聽器 - Google Cloud Messaging - BroadcastReceiver
先生,我在網上尋找答案,謝謝 –
你在使用什麼API?因爲我認爲ADT不再支持您實現服務器的方式。 – ampofila