Firebase Cloud Messaging with Android

lojorider lojo
Aug 23, 2017 · 1 min read

สำหรับผู้ที่ลงเข้ามากระผมแค่จดบันทึกเอาไว้เพื่อตัวเองดังนั้นท่านผู้ที่หลงทางเข้ามาอาจจะอ่านไม่รู้เรื่องแนะนำให้ไปอ่าน

รู้จัก Firebase Cloud Messaging (FCM) ตั้งแต่ Zero จนเป็น Hero

เริ่มจากการ Create Project Android แบบธรรมดาก่อน

เมื่อทำการพัฒนาตัว Android เสร็จแล้ว ก็มาถึงการส่งข้อความไปที่ ตัวอุปกรณ์โดยใช้ Server ของเรา ในที่นี้ผมใช้ Laravel 5.4 เป็น Server ในการยิง สัญญาณให้ FCM ส่งข้อความไปยัง Device ที่ได้ สับตะไคร้เอาไว้แล้ว

เบื้อต้นก็จัดนี่เลย

ลงข้อมูลตามวิธีการตามคู่มือ สรุปดังนี้

$ composer require brozot/laravel-fcm

จากนั้นก็

'providers' => [
// ...

LaravelFCM\FCMServiceProvider::class
]

จากนั้นก็

'aliases' => [
...
'FCM' => LaravelFCM\Facades\FCM::class,
'FCMGroup' => LaravelFCM\Facades\FCMGroup::class, // Optional
]

ไฟล์ .env

FCM_SERVER_KEY=my_secret_server_key
FCM_SENDER_ID=my_secret_sender_id

จากนั้นก็ไปหาวิธีใช้ตามที่มาของ package นั่นนะ

เป็นอันเสร็จพิธี
จอ บอ จบ

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade