SlideShare una empresa de Scribd logo
1 de 16
我的GCM時代
-推送訊息的實做分享
DIQI ANDROID APP DEVELOPER
台大資工所 張鈞為
Push and Pull Message
What is push message?
◦ Server 主動推送訊息到app端。
What is pull message?
◦ App 主動向Server 索取需要的訊息。
Why push is more difficult than pull?
◦ The IP address of each mobile device always change.
◦ Therefore, if we want to solve this problem, we have to set timer to connect to server periodically.
Fortunately, there are some useful tools to deal with this problem.
◦ Ex. Google cloud messaging
何時會用到推送訊息
最常見的就是Notification!
GCM overview
Google Cloud Messaging (GCM) is a service that allows
◦ Send data from your server to your Android device
◦ Receive messages from devices on the same connection.
It can deal with push message problem!
Two kinds of messages
Collapsible message
◦ May be replaced by a new message containing the same collapse key.
◦ Only the most recent message is relevant.
◦ Ex. Send-to-sync messages
Non-collapsible message
◦ Each individual message is delivered to the device.
◦ Ex. IM
Key Concepts
Components
◦ Client App
◦ 3rd-party Application Server
◦ GCM Connection Servers
Credentials
◦ Sender ID - Google API project ID
◦ Application ID – App’s Package name
◦ Registration ID – Issued by the GCM servers to the Apps. (Each device has one reg_id)
◦ Google User Account
◦ Sender Auth Token - API Key. Use as password in server
Architectural Overview
GCM Client
Use GoogleCloudMessage API
◦ Setup google play service SDK in the project.
Modify Manifest file
◦ Allow some permission (like internet…)
◦ Set a Receiver to receive GCM’s broadcast
◦ Set a Service to handle GCM message
Register for GCM
◦ Each device needs to register a unique registration ID.
◦ Let server keep the Reg id.
You can also implement
◦ User notification
◦ …
GCM Server
Two kinds of connections:
◦ GCM HTTP
◦ Downstream only: cloud-to-device.
◦ Synchronous messaging
◦ HTTP POST
◦ CCS(Cloud Connection Server, XMPP)
◦ Upstream and downstream (device-to-cloud, cloud-to-device).
◦ Asynchronous messaging
◦ JSON in XMPP message
Use device’s registration ID to send message.
GCM samples
單向:
Gmail : send notification after new mails arrived.
交通公具app:Server當車在進站前五分鐘、十分鐘時,提前通知使用者到站等候。
GCM samples
雙向:
◦ Aipu store(DiQi product):
在一開始的版本中,所有的傳輸都是使用GCM。
(現在的版本則是使用自己架的接口,原因稍後會說)
◦ Problem spider(和朋友合作的 prototype app) :
我們所有server和app之間的傳送都使用GCM。
However...
GCM 雖然方便,但是也有其做不到的地方。
◦ GCM在台灣國內或是世界絕大數國家都是十分方便的服務,但是總有例外。
◦ 在中國,因中國政府官方會擋google的所有服務,所以在中國要開發相關的功能時,就無法使用
GCM了。
◦ 還好,中國各大互聯網都有類似的服務。
◦ Ex. 百度、騰迅…。
百度雲推送(百度云推送)
由百度開發的雲端服務之一。以下為幾個特點。
◦ Server端有提供java, php的開發套件。
◦ Application端有提供android及ios。
◦ 網頁管理頁面。
雖然解決了中國無法使用GCM的問題,不過他本身不像GCM方便。雲推送僅提供推送
(push message, cloud-to-device)單向的服務。
Comparison
GCM:
◦ Pros: Easy to develop. GCM API can be simply used in Android Studio. (Google play service)
◦ Can send message in both direction.
◦ Cons: GCM cannot be used in China.
百度雲:
◦ 優點:解決在中國無法使用的問題。
◦ 缺點:僅能單向傳遞訊息。
◦ 其實不太容易import到自己的project中。
Reference
GCM官方教學:
https://developers.google.com/cloud-messaging/
百度雲:
http://developer.baidu.com/cloud/push
Thank you for listening

Más contenido relacionado

Similar a 我的GCM時代-推送訊息的實做分享

Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in androidRIA RUI Society
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messagingBhavana Sharma
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Mike Willbanks
 
GCM Android
GCM AndroidGCM Android
GCM Androidaswapnal
 
GCM with Pushbots
GCM with PushbotsGCM with Pushbots
GCM with PushbotsAshish RAj
 
Google Cloud Messaging
Google Cloud Messaging Google Cloud Messaging
Google Cloud Messaging Sandip Jadhav
 
Android push-applications-android
Android push-applications-androidAndroid push-applications-android
Android push-applications-androidwadise
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for AndroidRanjitha R_14
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017ketan Bordekar
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)Chinnayya Math
 
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiDicoding
 
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...MongoDB
 
Consumer driven contracts in java world
Consumer driven contracts in java worldConsumer driven contracts in java world
Consumer driven contracts in java worldYura Nosenko
 
Domain's Robot Army
Domain's Robot ArmyDomain's Robot Army
Domain's Robot Armydomaingroup
 

Similar a 我的GCM時代-推送訊息的實做分享 (20)

Google Cloud Messaging
Google Cloud Messaging Google Cloud Messaging
Google Cloud Messaging
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
 
Magda badita gcm
Magda badita  gcmMagda badita  gcm
Magda badita gcm
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)
 
GCM Android
GCM AndroidGCM Android
GCM Android
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
A Journey into Google Cloud Messaging
A Journey into Google Cloud MessagingA Journey into Google Cloud Messaging
A Journey into Google Cloud Messaging
 
GCM with Pushbots
GCM with PushbotsGCM with Pushbots
GCM with Pushbots
 
Google Cloud Messaging
Google Cloud Messaging Google Cloud Messaging
Google Cloud Messaging
 
Android push-applications-android
Android push-applications-androidAndroid push-applications-android
Android push-applications-android
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
 
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
 
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...
MongoDB World 2018: Building Serverless Apps with MongoDB Atlas on Google Clo...
 
Consumer driven contracts in java world
Consumer driven contracts in java worldConsumer driven contracts in java world
Consumer driven contracts in java world
 
Domain's Robot Army
Domain's Robot ArmyDomain's Robot Army
Domain's Robot Army
 

Último

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Último (20)

Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 

我的GCM時代-推送訊息的實做分享

Notas del editor

  1. 可能要定期pull或定期跟server更新ip位置
  2. A collapsible message is a message that may be replaced by a new message containing the same collapse key if it has yet to be delivered to the device. A non-collapsible message implies that each individual message is delivered to the device.
  3. 三個東西:1.我們的app 2.我們的server 3.gcm server 幾個認證的token: 特別要說reg id,每台手機就都有一份reg id,而server就是透過reg id 來傳給對應的device。 也就是說,其實真的在實作時,在server端對每一台device都應該要有一個欄位存相對應的reg id table。
  4. 示意圖。 如果使用gcm,我們不用自己刻一條從server到app的路,而只需在兩端透過gcm的api即可傳送資訊。
  5. 在client簡單的使用流程。
  6. server端的使用流程。 在gcm中,支援兩種connection模式。http和xmpp。 http只支援單向推送,使用http post的方式。 而xmpp則可以接受雙向溝通,資訊內容包成json的格式來傳送。 (說實話,xmpp背後的技術細節我不是很了解,但是google他們提供的sample code本身很容易修改使用。所以即便不懂也可以輕鬆上手。) 另外,如剛剛所說,我們自己的server這邊要table來記錄所有device的reg id,以便推送訊息。
  7. 說我們的故事~~~
  8. 網頁管理介面:除了server code以外,也可以手動在網頁介面直接來操作。 所以我們公司的產品中,雖然notification可以透過百度雲來推送,但資料傳送的部份還是得自己實刻。