Last active
October 18, 2016 23:53
-
-
Save ripzery/e910f49d2aece5b714bad27f8823573f to your computer and use it in GitHub Desktop.
gcm structure from tsl which uses notification payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10-18 23:58:21.170 25945-26010/com.socket9.thetsl D/MyGRcmListenerService: From: 197311876504 | |
10-18 23:58:21.172 25945-26010/com.socket9.thetsl I/MyGcmListenerService: Bundle[{google.sent_time=1476809900797, type=SERVICE BOOKING, google.message_id=0:1476809900806468%43ae439143ae4391, notification=Bundle[{body=รถยนต์หมายเลขทะเบียน ปดก-2558 ได้นัดหมายเข้าใช้บริการที่ TSL Auto Service ในวันที่ 21/09/2016 เวลา 15:19:00 น., title=SERVICE BOOKING}], message={"th_data":{"date":"Wednesday, September 21, 2016","time":"3:19 pm","type":"บริการแบบ A","branch":"ศูนย์บริการภูเก็ต"},"th":"รถยนต์หมายเลขทะเบียน ปดก-2558 ได้นัดหมายเข้าใช้บริการที่ TSL Auto Service ในวันที่ 21\/09\/2016 เวลา 15:19:00 น.","en_data":{"date":"Wednesday, September 21, 2016","time":"3:19 pm","type":"Service A","branch":"Phuket Service Center"},"en":"Date confirm 21\/09\/2016 Time 15:19:00"}, collapse_key=com.socket9.thetsl}] | |
10-18 23:58:21.173 25945-26010/com.socket9.thetsl I/MyGcmListenerService: รถยนต์หมายเลขทะเบียน ปดก-2558 ได้นัดหมายเข้าใช้บริการที่ TSL Auto Service ในวันที่ 21/09/2016 เวลา 15:19:00 น. |
จากการทดลอง comment code ส่วน build notification ขึ้นมาถ้าแอพรัน
background -> โชว notification
foreground -> ไม่โชว notification
สรุปว่าถ้ารันแบบ background ฟังก์ชั่น onMessageReceived จะไม่ทำงาน
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
บัค : intent extra is always null when app is in background.
สันนิษฐานสาเหตุการเกิดบัค : คลาส GcmListenerService ฟังก์ชั่น onMessageReceive ไม่ทำงานหรือ crash ข้างในฟังก์ชั่น (ไม่มี log เพราะ app ถูก killed)
สันนิษฐานสาเหตุของสาเหตุการเกิดบัค : app จะได้แค่ notification payload เมื่อแอพรัน background และ gcm จะเป็นคน build notification ขึ้นมาให้เอง (ดังนั้นอาจจะข้ามฟังก์ชั่น onMessageReceive ไปเลย) แต่ถ้ารัน foreground(active) จะได้ทั้ง notification และ data payload ซึ่งตอนนี้ app ใช้งานแค่ data payload เท่านั้น และเมื่อรัน background จะไม่มี data payload ให้ใช้
สรุป : gcm skip onMessageReceive ตอน background ไม่ก็ gcm ไม่ได้ skip แต่ส่ง notification payload มาให้ใช้แทน (ซึ่งไม่ได้ใช้)
คิดว่ากรณีแรกเป็นไปได้มากกว่า
จาก doc ของ gcm
อ้างอิง : https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages