Skip to content

Instantly share code, notes, and snippets.

@ripzery
Last active October 18, 2016 23:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripzery/e910f49d2aece5b714bad27f8823573f to your computer and use it in GitHub Desktop.
Save ripzery/e910f49d2aece5b714bad27f8823573f to your computer and use it in GitHub Desktop.
gcm structure from tsl which uses notification payload
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 น.
@ripzery
Copy link
Author

ripzery commented Oct 18, 2016

บัค : 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

screen shot 2016-10-19 at 12 15 08 am

อ้างอิง : https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages

@ripzery
Copy link
Author

ripzery commented Oct 18, 2016

จากการทดลอง comment code ส่วน build notification ขึ้นมาถ้าแอพรัน

background -> โชว notification
foreground -> ไม่โชว notification

สรุปว่าถ้ารันแบบ background ฟังก์ชั่น onMessageReceived จะไม่ทำงาน

@ripzery
Copy link
Author

ripzery commented Oct 18, 2016

About payload

image

จาก Use scenario แล้วคิดว่าถ้า server เอา notification payload ออก อาจจะทำให้ฟังก์ชั่น onMessageReceived ทำงาน

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment