简体   繁体   中英

Android Push Notification using firebase from ruby on rails

How to send push notification to Android Mobile using firebase from ruby on rails. I know rails-push-notifications and others but I want using firebase so kindly provide documentation for how to send push notification using firebase in android application.

Worked for me...

Add this gem 'fcm' into your gemfile, run the command bundle install .

Create a method and paste this:

require 'fcm'

fcm = FCM.new(server_key) # Find server_key on: your firebase console on web > tab general > web api key

registration_ids= [device_keys] # Array of keys generated by firebase for devices 

options = {
        priority: "high",
        collapse_key: "updated_score", 
        notification: {
            title: "Message Title", 
            body: "Hi, Worked perfectly",
            icon: "myicon"}
        }

response = fcm.send(registration_ids, options)

more about gem fcm

I hope it helped you.

You can find this fcm gem that allows you to send notification with Firebase Cloud Messaging.

require 'fcm'

fcm = FCM.new("my_api_key")
# you can set option parameters in here
#  - all options are pass to HTTParty method arguments
#  - ref: https://github.com/jnunemaker/httparty/blob/master/lib/httparty.rb#L29-L60
#  fcm = FCM.new("my_api_key", timeout: 3)

registration_ids= ["12", "13"] # an array of one or more client registration tokens
options = {data: {score: "123"}, collapse_key: "updated_score"}
response = fcm.send(registration_ids, options)

YM

There is no need to use Gem, it does not work for my application. but I'm using React to use POST Method ( https://fcm.googleapis.com/fcm/send ) with the following header contents:

{
    server_key: web_api_key_on_console_web
},

body: {
    to: Mobile_token_created_by_phone,
    notification: {
        title: "Judul",
        body: "Isi pesan"
    },
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM