Using pushwoosh for android

Hi, 

I would like to ask if anyone can give a step by step guide on what I should do to implement push notification on android using corona. I am really confused on what/how I will implement it. I am looking forward for your replies. Thank you

if you just want notifications for Android devices, you should look at the googlePushNotifications sample code

Thank you. I will look through it. I would like to have iOS push notifications as well, can both of them have the same code?

The Corona SDK code between Android and iOS is the same.  What you have to manage though is when you get the registration event from the system and you’re calling the PushWoosh device registration, the data they expect for Android is different than iOS and you will have to adapt that registration code accordingly.

Rob

Oh, I see. I think I may have to study further about it. Thank you

I’m not using it but I tested it few weeks back. This is my code, I guess it should work. 

[lua]

local function registerWithPushWoosh (token) 

    – Register device with PushWoosh. PushWoosh account and setup required.

    

    local DeviceID = token

    local PW_APPLICATION = “XXXXXXXXXXXXXXXXXXXXXXX”    --use your app id in pushwoosh

    local PW_URL = “https://cp.pushwoosh.com/json/1.3/registerDevice

    local function networkListener( event )

            if ( event.isError ) then --error occurred notify user

                native.showAlert( “Notification Registration Failed”, “An Error Contacting the Server has Occurred”, { “OK” } )

            else

                --Registration worked

            end

    end     

    local commands_json = {

         [“request”] = {

            [“application”] = PW_APPLICATION,

            [“push_token”] = DeviceID,

            [“language”] = system.getPreference(“ui”, “language”),

            [“hwid”] = system.getInfo(“deviceID”),

            [“timezone”] = 3600, – offset in seconds

            [“device_type”] = 3 – 1 – iphone, 2 – blackberry, 3 – android, 4 – nokia, 5 – WP7, 7 – mac

        }

    }

    local jsonvar = {}

    jsonvar = json.encode(commands_json)

    local post = jsonvar

    local headers = {}

    headers[“Content-Type”] = “application/json”

    headers[“Accept-Language”] = “en-US”

    local params = {}

    params.headers = headers

    params.body = post

    network.request ( PW_URL, “POST”, networkListener, params )

end

local function onNotification( event )

    if event.type == “remoteRegistration” then

        registerWithPushWoosh(event.token) 

    end

end

[/lua]

BTW before starting this I recommend having the Corona Android push example tested and working if you are unsure about how this stuff works.

if you just want notifications for Android devices, you should look at the googlePushNotifications sample code

Thank you. I will look through it. I would like to have iOS push notifications as well, can both of them have the same code?

The Corona SDK code between Android and iOS is the same.  What you have to manage though is when you get the registration event from the system and you’re calling the PushWoosh device registration, the data they expect for Android is different than iOS and you will have to adapt that registration code accordingly.

Rob

Oh, I see. I think I may have to study further about it. Thank you

I’m not using it but I tested it few weeks back. This is my code, I guess it should work. 

[lua]

local function registerWithPushWoosh (token) 

    – Register device with PushWoosh. PushWoosh account and setup required.

    

    local DeviceID = token

    local PW_APPLICATION = “XXXXXXXXXXXXXXXXXXXXXXX”    --use your app id in pushwoosh

    local PW_URL = “https://cp.pushwoosh.com/json/1.3/registerDevice

    local function networkListener( event )

            if ( event.isError ) then --error occurred notify user

                native.showAlert( “Notification Registration Failed”, “An Error Contacting the Server has Occurred”, { “OK” } )

            else

                --Registration worked

            end

    end     

    local commands_json = {

         [“request”] = {

            [“application”] = PW_APPLICATION,

            [“push_token”] = DeviceID,

            [“language”] = system.getPreference(“ui”, “language”),

            [“hwid”] = system.getInfo(“deviceID”),

            [“timezone”] = 3600, – offset in seconds

            [“device_type”] = 3 – 1 – iphone, 2 – blackberry, 3 – android, 4 – nokia, 5 – WP7, 7 – mac

        }

    }

    local jsonvar = {}

    jsonvar = json.encode(commands_json)

    local post = jsonvar

    local headers = {}

    headers[“Content-Type”] = “application/json”

    headers[“Accept-Language”] = “en-US”

    local params = {}

    params.headers = headers

    params.body = post

    network.request ( PW_URL, “POST”, networkListener, params )

end

local function onNotification( event )

    if event.type == “remoteRegistration” then

        registerWithPushWoosh(event.token) 

    end

end

[/lua]

BTW before starting this I recommend having the Corona Android push example tested and working if you are unsure about how this stuff works.