Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android Push Notifications with Urban Airship

Hi everyone,

I'm currently building an app on iOS and Android.
First thing I want you to know: the push notifications were quite easy to set up on iOS. Works great so far.

Troubles began when I tried to develop the Android version. I found several useful links about that, but I wasn't able to connect the dots yet.
So I thought it would be a good idea to ask: has someone succeeded to set up push notifications in Android?

Here are the things I've read/tried:

  • Official UrbanAirship announce of Android Push Notification support. But they seem to install their own "app" to enable push notifications for devices with Android SDK > 1.5
  • The official Google documentation for C2DM, which enable push notifications for devices with Android>2.2 only
  • The module provided by the Titanium team. It says it's compatible with Android and iPhone…but what is the equivalent of the Ti.Network.registerForPushNotifications method? If there is no equivalent (and I think it's the case, since the documentation says it's an iPhone only method), how can I retrieve the token? From the documentation of this module: token[object]: A blob object containing the device's token. This should be obtained by a Ti.Network.registerForPushNotifications() callback.
  • Here is a ticket (#1919) which contains an interesting discussion about Android Push Notifications implementation with C2DM
  • The GitHub repo of the source code indicated in the ticket #1919. I could build the module, but I couldn't figure out the correct use of it and what it offers exactly.

Sorry for the lengthy post.
Any help is greatly appreciated! :)

Cheers,
Arnaud.

— asked May 5th 2011 by Arnaud Brousseau
  • android
  • notifications
  • push
  • urbanairship
2 Comments
  • Hi again,

    I've dug into the C2DM approach a bit more, and it still seems a bit experimental…at least too experimental to be considered as "ready for production". Another drawback is the lack of support for device with Android < 2.2.

    For those interested in this approach, a very good tutorial can be found here (but I didn't manage to make things work since you need to set up your own 'application server' – that's where I stopped).

    So I'm choosing the UrbanAirship-based solution. I might be ready to pay for the package provided by the Titanium Team if it's working correctly. Currently, I have a hard time making it work.

    As said above, I don't see how I can retrieve the token necessary to make the registerDevice() call.
    Anyone has a clue about that ? Someone has already succeeded to push notifications to an Android device ?

    Cheers, Arnaud.

    — commented May 9th 2011 by Arnaud Brousseau
  • Any news about this?

    — commented July 15th 2011 by Julian Lindblad

6 Answers

  • I'm interested in this as well.. trying to import my push enabled app from iPhone to Android.

    Thanks for the detailed info Arnaud.

    — answered May 15th 2011 by Idan Jan
    permalink
    0 Comments
  • does you guys found anything. i am stuck on this also

    — answered April 4th 2012 by Abrar Sair
    permalink
    0 Comments
  • Interested in this as well!

    — answered June 26th 2012 by Bryan Chua
    permalink
    0 Comments
  • It is awesome the lack of support on this. Seems like everyone is wondering the same thing and Ti is doing nothing about it.A year has passed and we still dont know how to register android device using UA module

    — answered June 27th 2012 by Mobile Developer
    permalink
    0 Comments
  • Hi guys,

    I registered to UrbanAirship, but I can't receive push notification on the device. On UrbanAirship, it said that it's goes out, but I can't get it on the phone.

    Here's the code for Android:

    
    UrbanAirship.pushEnabled = true;    
    UrbanAirship.showOnAppClick = true;
    UrbanAirship.tags = ["android"];
    
    //var c2dm = UrbanAirship.c2dmId;
    
    function eventCallback(e) {
    
        if (e.clicked) {
    
            Ti.API.info('User clicked a notification');
        } else {
    
                Ti.API.info('Push message received');
        }
    
        Ti.API.info('Message: ' + e.message);
        Ti.API.info('Payload: ' + e.payload);
    }
    
    function eventSuccess(e) {
    
        Ti.API.info('Received device token: ' + e.deviceToken);
    }
    
    function eventError(e) {
    
    Ti.API.info('Error:' + e.error);
    
        var alert = Ti.UI.createAlertDialog({
            title: 'Error',
            message: e.error
        });
    
        alert.show();
    }
    
    UrbanAirship.addEventListener(UrbanAirship.EVENT_URBAN_AIRSHIP_CALLBACK, eventCallback);
    UrbanAirship.addEventListener(UrbanAirship.EVENT_URBAN_AIRSHIP_SUCCESS, eventSuccess);
    UrbanAirship.addEventListener(UrbanAirship.EVENT_URBAN_AIRSHIP_ERROR, eventError);
    

    Don't forget the airshipconfig.properties file. You must put it in your [APPDIR]/platform/android/bin/assets/airshipconfig.properties folder.

    Look at the documentation. It's help me to register. Now I have to figured out why I don't get the push.

    Hope this help.

    Daniel

    — answered July 4th 2012 by Daniel Lusignan
    permalink
    9 Comments
    • My keeps saying that I dont have a license for the module, but it works fine in the iphone.
      How id you get it to pass the validation?

      — commented July 5th 2012 by Mobile Developer
    • Hi! What do you need by validation? Registration? In my model, the registration is done on the PHP side.

      I finally get it to work 100% with this post

      Thanks.

      — commented July 5th 2012 by Daniel Lusignan
    • No I meant the module, it keeps saying "license violation detected", however, the ios build works fine

      — commented July 5th 2012 by Mobile Developer
    • Ha ok, I pay the monthly fee.

      — commented July 5th 2012 by Daniel Lusignan
    • well, we have it a subscription.

      — commented July 5th 2012 by Mobile Developer
    • Ok! I never receive this message. Try to cancel your subscription and resubscribe. There is two UrbanAirship module. One for iOS only and the other for both iOS and Android. I pretty sure you have the good one but just in case.

      — commented July 5th 2012 by Daniel Lusignan
    • Your problem might be that you never register the device with UA. You have to get the APID (not sure how actually and am curious on how to do it) and send to UA.

      The example doesnt show how to get the id either.

      — commented July 6th 2012 by Mobile Developer
    • The APID is generated by te module wen you register. There is three callback method when you register. In the success method, you access the property deviceToken of the returning object and there you have your APID.

      — commented July 6th 2012 by Daniel Lusignan
    • Yeah, in IOS is registerForPushNotifications but i dont see in your code when you do register ? Something similar to the call in iOS.

      — commented July 9th 2012 by Mobile Developer
  • Yeah, i have the right one since the android package is there, and I cant find the way to remove the module cuz i was looking to do that before. Some modules have a way to remove once you mouse over it but UA is one of the ones that when you mouse over the black settings layer is not there.
    So, any ideas how you remove UA from 'your products'?
    thanks

    — answered July 5th 2012 by Mobile Developer
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.