3

EDIT 3

I use RhoMobile to get device_token, which I am getting to server

def register_device
    @person = Person.find(:first)
    unless System.get_property('is_emulator')
     url = "#{@base}/users/#{@person.remote_id}/register_device?os=#{System.get_property('platform')}&device_token=#{System.get_property('device_id')}"
     Rho::AsyncHttp.get(
        :url => url,
        :headers => {'User-Agent' => Rho::RhoConfig.user_agent}
      )
    end
    finish_and_go_to_venue
  end

EDIT 2

Have device_token but keep getting Error=NotRegistered

EDIT

OK, so first mistake was using the wrong device ID. Now working, but phone not alerting with message.

ORIGINAL

First time user of sending android Push messages from rails server.

Using https://github.com/sghael/speedy_c2dm

I registered with google and received white list email.

trying test.rb below, but nothing gets sent to phone.

require 'rubygems'
require 'bundler'
Bundler.setup(:default, :development)
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'speedy_c2dm'


TEST_EMAIL = "my_push_email@gmail.com"
TEST_PASSWORD = "MY_PASSWORD"
TEST_REGISTRATION_ID = "DEVICE_TOKEN_RECEIVED_FROM_PHONE"

speedyC2DM = SpeedyC2DM::API.new(TEST_EMAIL, TEST_PASSWORD)

options = {
  :registration_id => TEST_REGISTRATION_ID,
  :message => "Hi!",
  :extra_data => 42,
  :collapse_key => "some-collapse-key"
}


response = speedyC2DM.send_notification(options) 
pcasa
  • 3,710
  • 7
  • 39
  • 67

1 Answers1

1

Try adding a Controller named Push and inside the controller you need to have the following:

require 'rho/rhocontroller'
require 'helpers/browser_helper'

class PushController < Rho::RhoController
  include BrowserHelper

  def push_callback

    Alert.show_popup @params['message'] #this will show you a popup with your push message
    puts "push_callback : #{@params}" #you'll see what you are receiving with this
    "rho_push"  #to run rhodes push command processing (for alerts, sounds, etc…)
  end


end

you need to set your application to call this by adding the following line to your application.rb

System.set_push_notification "/app/Push/push_callback", ''

Also, did you configure your build.yml correctly?

android:
  push:
    notification: always
    sender: your-sender-email@gmail.com
capabilities:
  - push
  - vibrate

At least with my app, I need to have the application running in order to get the message.

marimaf
  • 5,382
  • 3
  • 50
  • 68