A really simple example to demonstrate how to use GCM
Steps to use the example project:
- Create a
google-servicesconfiguration file here. Insert the package name as "com.alphabet7.hellogcm" if you don't change the package name in this project. - Save your
SENDER_IDandSERVER_KEYinformations. - Download the
google-services.jsonfile then save it to the/appfolder. - Insert your
SENDER_IDat theGcmRegistrationIntentService.java. - Run the project, check the Android Monitor, and wait for the Registration Token to appear in the Log.
- Use postman with the template here, and insert your
SERVER_KEYandDEVICE_REGISTRATION_TOKEN/IDin the Body and Header. Alternatively, you can also use this website, insert theSERVER_KEY,DEVICE_REGISTRATION_TOKEN/ID, and this message:{"content":"Congratulations, GCM push success"}. Then click Submit/Send. - The push notification will appear on your device.
Contoh sederhana untuk menggunakan GCM (Google Cloud Messaging)
Langkah-langkah untuk menjalankan project ini:
- Buat file konfigurasi
google-servicesdi sini. Masukkan package name-nya sebagai "com.alphabet7.hellogcm" jika kamu tidak mau merubah package name pada project ini. - Simpan data
SENDER_IDdanSERVER_KEYyang diberikan. - Unduh file
google-services.jsonkemudian simpan di folder/appproject ini. - Masukkan data
SENDER_IDkamu padaGcmRegistrationIntentService.java. - Run project ini, buka Android Monitor, kemudian tunggu sampai Registration Token Device-nya muncul di Log.
- Gunakan Postman dengan template berikut, lalu masukkan data
SERVER_KEYdanDEVICE_REGISTRATION_TOKEN/ID-nya pada Body dan Header. Selain cara itu, kamu juga bisa menggunakan website ini, masukkanSERVER_KEY,DEVICE_REGISTRATION_TOKEN/ID, dan message ini:{"content":"Congratulations, GCM push success"}. Lalu klik Submit/Send - Push Notification akan tampil di device kamu.