The Space For App Developers

Beyond Plain Old HTML Objects

as3c2dm – AIR native extension to push notifications with C2DM

with 62 comments

In this short video recording you will see my new and first AIR native extension (ANE) that I created for C2DM (Android Cloud to Device Messaging Framework).

C2DM allows you to push notifications to your Android applications. The cool thing about it is that your application doesn’t have to run in the background in order to receive messages. In this case, my ANE creates a notification with a specified ticker, title and text. When the user taps on the notification it runs an AIR application and passes the sent message text that is displayed in the app. Check out the magic for yourself in the video below.



The source code is available here. You can also download the packaged ANE and the C2DM Messanger app from here and here.

Check out some more already built ANE’s here.

Written by Piotr Walczyszyn

September 29th, 2011 at 6:14 pm

Posted in Examples,Recording

Tagged with , , , ,

62 Responses to 'as3c2dm – AIR native extension to push notifications with C2DM'

Subscribe to comments with RSS or TrackBack to 'as3c2dm – AIR native extension to push notifications with C2DM'.

  1. [...] as3c2dm – AIR native extension to push notifications with C2DM at Space of Flex/AIR technologies. //Two words ‘VERY nice’ thanks for sharing, this will no doubt save one item on many peoples ‘todo list’ (smile) LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); LD_AddCustomAttr("LangId", "1"); LD_AddCustomAttr("Autotag", "technology"); LD_AddCustomAttr("Tag", "android"); LD_AddCustomAttr("Tag", "flexairflash"); LD_AddSlot("wpcom_below_post"); LD_GetBids(); Like this:LikeBe the first to like this post. [...]

  2. Is there a possibility to add the receive listening upon installation before user is running the application for the first time ?

    Gadi

    2 Oct 11 at 10:55 pm

  3. @Gadi I don’t think so, at least not with current implementation in as3c2dm because before you can start using it you have register users phone and the application in c2dm service. This is done through AIR part of the app when the app receives back a registration event.

    Piotr Walczyszyn

    3 Oct 11 at 2:17 pm

  4. [...] AS3C2DM Lets you create custom push notifications for your Android applications. [...]

  5. Hi,

    I have android jar that calls over JNI .so library. Now I want to add it in AIR app. However when I pack all together in AIR apk, it throws linkage exception. I unpacked APK and saw that .so shared libs are not there.
    Any thoughts how can fix this problem?
    Thanks,
    Marin

    Marin

    5 Oct 11 at 2:31 pm

  6. Dlaczego nie po polsku ….

    Polski evangelista :) prosimy o kilka tutoriali w polskim języku , łatwiej będzie nam co nieco zrozumieć :)

    dziękuję (również w imieniu rodaków )

    Pozdrawiam

    Paweł

    5 Oct 11 at 9:43 pm

  7. Hi Piotr, i’ve signed for android c2dm and made a simple android app exactly like yours, the problem is that i don’t receive any notifications and i can’t register either and i’m assuming this is because the android manifest, can you please tell me what changes should i make here

    yonodo

    14 Oct 11 at 3:27 pm

  8. @yonodo did you register your app id with air. prefix and .debug suffix?

    Piotr Walczyszyn

    14 Oct 11 at 5:14 pm

  9. @Piotr: I’ve registered my app with com.dg.testapp

    yonodo

    15 Oct 11 at 12:43 pm

  10. @yonodo you should register with air. prefix because this is what AIR runtime adds to your app id in the background. Also when you are running in the debug mode it adds .debug at the end of id, so you should register for both and Google C2DM registration form.

    Piotr Walczyszyn

    16 Oct 11 at 3:56 pm

  11. Hi Piotr,
    I downloaded as3c2dm-example.fxp, and tried to import to my 4.5 premium version flash builder. When I am importing, it shows java null pointer exception. Do you have any suggestions for that? Again, I tried to build my own project with the .ane file that you provided, but my flash builder can not recognize the com.riaspace.c2dm package.I need your suggestions.

    Regards,

    Nahid

    Nahid

    18 Oct 11 at 6:41 am

  12. Hi, I’m trying to use this ANE as you are in your example but the c2dm.register method never dispatches a REGISTERED nor ERROR event.

    Any clue?

    Gilmar.

    Gilmar

    26 Oct 11 at 6:20 pm

  13. @Gilmar I suspect that you have a mismatch of your application id and what you registered at google c2dm service registration form.

    Remember that you have to register app id with air. prefix and .debug suffix if you are running in debug mode which you probably do during development.

    p.

    Piotr Walczyszyn

    27 Oct 11 at 2:47 pm

  14. Hi Piotr,

    do you have an estimate how hard it would be to get iOS server based push to work?

    We would need this shortly and maybe we could also sponsor the development for this…

    or start learning objective-c

    :-)

    Best,
    Cedric

  15. Hi,
    I have just release a blog post about creating a NativeAlert extension for AIR. It includes multiple buttons and dispatches ActionScript events when the user selects one of those buttons.
    the post can be found here.
    http://www.liquid-photo.com/2011/10/28/native-extension-for-adobe-air-and-ios-101/
    The source is on github and you can download the NativeAlert.ane file directly also

    Hope you guys like it.

    Anthony

    30 Oct 11 at 1:05 am

  16. Hi Piotr,
    I am sorry that I could make my question clear to you. Just a simple question now. Is it possible to use ane file in 4.5 premium version flash builder. If yes then how?

    Regards,

    Nahid

    Nahid

    30 Oct 11 at 7:21 pm

  17. Hi, Piotr!

    I also am getting the Java Null Pointer exception when attempting to load or build the sample. Using Flash Builder 4.5 Premium on a Mac w Snow Leopard.

    Thanks!

    Pete

    Pete

    3 Nov 11 at 7:24 pm

  18. Pete, I think the problem is that you are importing the project into FB 4.5, and the source files are updated for the 4.6 prerelease version.

    Leonardo

    4 Nov 11 at 8:36 am

  19. Hi Piotr, many thanks for putting this together for the community, I cant tell many people will owe you one :)
    I do have a problem getting all this figured and would like some assistance if possible.
    Question 1) namespace used as registration for C2DM, say I desire to signup with com.company.product (which is my app home ns), according to your suggestion we should sign with 2 namespaces:
    a) air.com.company.product (used for production environment).
    b)air.com.company.product.debug (used for debugging in flex builder).

    Leonardo

    4 Nov 11 at 8:47 am

  20. Question 2) What do we need to do to set this up in FB 4.5 ( I know the project was recently updated to 4.6 – prerelease – which offers a more nicely UI to do it).

    I tried to figure it out by following this: http://blogs.adobe.com/actionscriptdocs/2011/10/using-flash-builder-4-5-1-to-compile-an-air-app-that-uses-a-native-extension.html

    But that didnt help much. To accomplish step one from the native extension setup (above), what should it do?
    Add this http://snipt.org/Qoj5 (XML)
    to my app.xml manifest?

    If yes or not?
    Do I need to do anything or set my ns value somewhere to make this work? eg: air.com.company.product ?

    Thanks In advance,
    Leo

    Leonardo

    4 Nov 11 at 8:47 am

  21. @Leonardo this is correct you should register with air prefix and for development with debug suffix.

    Also you have to properly configure Android permissions which should contain your app id.

    p.

    Piotr Walczyszyn

    4 Nov 11 at 3:22 pm

  22. Just wanted to say ‘thanks very much’ for this. A small demo app like this is perfect to show how this c2dm functionality works.
    Great work!
    Alex

    Alex

    6 Nov 11 at 2:48 pm

  23. Thank you, Piotr! Works perfectly!

    I would like to add to the wishlist that the extension could use the 36 or 48 px version of the application icon – if possible. Scaling down the 72 px version doesn’t always look good. I had to simplify the 72 px application icon to make the notifications look decent.

    Thanks…

    Anders

    23 Nov 11 at 2:44 pm

  24. Another thing to the wishlist: A function to remove all notifications for the app. I have noticed many of my users click the application icon instead of the notification, which leaves the notification in the status bar. It would be nice to have the possibility to delete all notifications for the app (“all read”).

    Anders

    24 Nov 11 at 4:11 pm

  25. Hi Piotr, great work!

    Just one small issue though, with flex 4.6 if an app is packaged with the captive Air Runtime, the icon that displays for notifications is the adobe air icon and not the application’s own icon.

    When not using the captive runtime the app’s own icon is used properly.

    I know this isn’t the fault of your code, but do you know of a workaround to use the captive runtime, and still have your own app icon show up on push notifications?

    Michael

    6 Dec 11 at 4:23 pm

  26. Hi Piotr, i’ve tried your example but when i run the cd2m app on my device and click on Register, after a few seconds, i get a popup saying the app cause and error and a force close button.
    Any help? Thanks

    Antonio

    9 Dec 11 at 12:25 pm

  27. @Antonio I never had an issue like that.
    p.

    Piotr Walczyszyn

    12 Dec 11 at 4:39 pm

  28. [...] Worth reading: Adobe Blogs: iOS5 support for AIR/Using external SDKs to package apps MFMailComposeViewController Class Reference Adobe Docs: Building the ActionScript library of a native extension Native Alert iOS native extension tutorial AIR Native Extension Example: iBattery for iOS as3c2dm – AIR native extension to push notifications with C2DM [...]

  29. Hi Piotr, i’m using FB 4.6 PreRelease on a Samsung Galaxy S2 and always get the error. Can i send you my sample please? I need help urgently!!!!

    Antonio

    14 Dec 11 at 1:45 pm

  30. Hi again, i can use the .ane file as it comes. I added as extension and can i use the namespace com.riaspace.etc or must download the code and recompile with my com.myapp..etc??

    Antonio

    14 Dec 11 at 2:24 pm

  31. @Cedric and others interested in iOS version

    I’ve created a native extension for iOS push notifications (using APNs), you can give it a try.
    It’s still under development, but fully functional.

    Extension and example app can be found on GitHub
    https://github.com/pkoscierzynski/NativeAPNService

    Another AIR extension made in Poland :)

  32. How do I add vibration & sound to the messenger? I couldn’t find the format required anywhere.

    I added the vibrate permissions to the app and tried to add in the btnSend_clickHandler function this:

    obj["data.vibrate"] = 1000;
    obj.vibrate = 1000;

    Arik

    19 Dec 11 at 2:59 pm

  33. @Arik for vibrations and sound you should use different ANE. You can find more here: http://www.adobe.com/devnet/air/native-extensions-for-air.html

    Piotr Walczyszyn

    19 Dec 11 at 3:37 pm

  34. Hello,
    I have some silly questions, but those are taking a lot of time. If anyone answers my questions, that will save my time. I don’t understand how to register with air prefix and with debug suffix. Can anyone help me how to do that? Again when I am registering my appliction with google c2dm, what would be “Package name of Android app”? I created an application named PushNotification where I am usning as3c2dm ANE file. Thanks in advance for your patience to answer my questions.

    Thanks,

    Nahid

    Nahid Shah

    21 Dec 11 at 2:04 am

  35. Hi Piotr, Did you mean the Local Notifications ANE?
    I want the network notification to vibrate and play sound. Isn’t it possible?

    Thanks.

    Arik

    26 Dec 11 at 2:17 am

  36. Hi,
    I tried your example but I received message:
    Message was sent, returned result object:
    “id=0:1325154727754640%f720122c00000031

    and don’t have any message go to my phone.
    help me please Piotr.
    thanks you.

    hoangtuanhai

    29 Dec 11 at 11:34 am

  37. Hello,
    I have some silly questions, but those are taking a lot of time. If anyone answers my questions, that will save my time. I am registering my appliction with google c2dm, what would be “Package name of my Android app”? I created an application named PushNotification where I am usning as3c2dm ANE file. Thanks in advance for your patience to answer my questions.

    Nahid Shah

    11 Jan 12 at 3:52 am

  38. Seems like the video on this pageis broken. Is there anyway you could write up or link to a step by step tutorial on how to get this to work in our own projects? Including what android permissions need to bechanged inside the AIR XML.

    Thanks a lot.

    James Lynn

    11 Jan 12 at 10:26 pm

  39. @James your wish has materialized ;)

    http://youtu.be/qddHBBQHBGE

    Piotr Walczyszyn

    12 Jan 12 at 7:12 pm

  40. I am also requesting for a step by setp video tutorial. Sometime its really confusing for the new developers to follow what exactly is happening.

    Nahid Shah

    13 Jan 12 at 12:15 am

  41. My getting started with as3c2dm video tutorial is here: http://www.riaspace.com/2012/01/as3c2dm-getting-started/

    IF YOU HAVE ANY ISSUES PLEASE COMMENT IN THE GETTING STARTED POST!

    Piotr Walczyszyn

    13 Jan 12 at 11:51 am

  42. Hi piotr,
    Does as3c2dm works in pure as3 without Flex ?

    Thanks

    Ben

    24 Jan 12 at 5:12 pm

  43. @Ben

    Yes it should work with pure AS3 projects.

    p.

    Piotr Walczyszyn

    24 Jan 12 at 5:30 pm

  44. This is a great extension

    I really appreciate that fact that you included all the components of the extension (native code and AS3 code), so it’s a great example to look at when learning how to develop extensions.

    Thanks a lot for sharing :)

    Julian

    31 Jan 12 at 6:37 am

  45. [...] es gibt eine as3c2dm native extension — hier. [...]

  46. Hi,
    Can’t manage to install the C2DMMessenger.air working.
    https://github.com/downloads/pwalczyszyn/as3c2dm/C2DMMessenger.air
    Has anyone met this problem recently?
    Thanks in advance.
    Best regards,
    Guillaume

    Guillaume GARCIA

    15 Feb 12 at 11:47 pm

  47. Hi, I also can´t install C2DMMessenger.air.
    Does anyone have a solution for this?

    thanks

    Jorge A.

    16 Feb 12 at 12:33 pm

  48. Hi Piotr, many thanks for this great example.

    Though I’m wondering, why are you specifying “” in the manifest.xml file, while C2DM and Adobe Air are supported from SDK version 8 and onward? Any particular reason?

    Michiel

    21 Feb 12 at 11:27 am

  49. Commenting system ate part of my comment. Between “” should be: “uses-sdk android:minSdkVersion=”8″”

    Michiel

    21 Feb 12 at 11:28 am

  50. And by 8 I mean 10. The example manifest tells us 10.

    Michiel

    21 Feb 12 at 11:30 am

  51. Hi Piotr, i’ve tried your sample and runs perfect. When i try the same on my app i receive this error on FB when compiling and it’s only happens when incorporate your library and modifications on the manifest file. If i delete all de mods, the apps compile and runs ok:

    An internal error occurred during: “Launching Android Version”.
    java.lang.NullPointerException

    Any hints? Thanks

    anibol

    22 Feb 12 at 9:55 am

  52. Hello Guys! I have a problem with .ane extension import in this example (I’m using FB 4.6 and I made all necesarry changes required see: http://www.youtube.com/watch?v=qddHBBQHBGE&feature=player_embedded#!) but no result.

    All I have is this error: VerifyError: Error #1014: Class com.riaspace.c2dm::C2DM could not be found.

    I just don’t get it: I started new Android Mobile Project. I imported the .ane extension and in scripting added some imports like:

    import com.riaspace.c2dm.C2DM;
    import com.riaspace.c2dm.events.C2DMErrorEvent;
    import com.riaspace.c2dm.events.C2DMRegistrationEvent;

    Work’s fine.

    But when I tried to declare: private var c2m:CMD

    I get same error.
    Can anyone help me with this?

    Best regards!

    Ciprian

    22 Feb 12 at 11:38 am

  53. Hi Piotr.

    Good work. The sample works very well.

    Thanks for share with the world.

    Agustín Muñoz

    16 Mar 12 at 1:01 pm

  54. don’t get it: I started new Android Mobile Project. I imported the .ane extension and in scripting added some imports like:

    import com.riaspace.c2dm.C2DM;
    import com.riaspace.c

    amorsitör

    23 Mar 12 at 4:24 pm

  55. Am i the only one who can’t fund the client side app? i can’r open the AIR messenger either- it says the installation is corrupted.

    please help.

    yonny

    28 Mar 12 at 4:11 pm

  56. Thank you for this!
    Sadly the C2DM Messenger isn’t working. Says the file is corrupted :/

    Daniel

    30 Apr 12 at 5:03 am

  57. Any ideas how to give this notification the default behavior?(ring and vibrate)

    Daniel

    30 Apr 12 at 10:50 pm

  58. [...] you went through Piotr Walczyszy’s tutorial about an Air Native Extension (ANE) to work with C2DM Android service to push messages to Adobe Air [...]

  59. OK, I fixed the sound and vibration problem. Now it works according to the phone’s default configuration. More about it in my blog.
    http://www.flexbrasilia.com.br/blog/2012/05/as3c2dm-sound-and-vibration-fix/

    Daniel

    1 May 12 at 9:00 am

  60. Hello Piotr,

    I have the same problem as Ciprian wrote in February:

    “I have a problem with .ane extension import in this example (I’m using FB 4.6 and I made all necesarry changes required see: http://www.youtube.com/watch?v=qddHBBQHBGE&feature=player_embedded#!) but no result.

    All I have is this error: VerifyError: Error #1014: Class com.riaspace.c2dm::C2DM could not be found.

    I just don’t get it: I started new Android Mobile Project. I imported the .ane extension and in scripting added some imports like:

    import com.riaspace.c2dm.C2DM;
    import com.riaspace.c2dm.events.C2DMErrorEvent;
    import com.riaspace.c2dm.events.C2DMRegistrationEvent;

    Work’s fine.

    But when I tried to declare: private var c2m:CMD

    I get same error.”

    Please help me with this! I event tried the new .ane file from here: http://www.flexbrasilia.com.br/blog/2012/05/as3c2dm-sound-and-vibration-fix/ – same result.

    Thank you!

    Eileen

    8 May 12 at 11:11 am

  61. Eileen, even I (owner of FlexBrasilia.com.br) am having this same issue. I just woke up today, tried to debug the app that was working fine before and now it’s not working anymore. My bet is on an FB update. Because I’m also having an Alert from FB about error/warning on the ane when I try to debug it. And I never got this Alert before. I’ll come back here if I find the problem.

    Daniel

    16 May 12 at 9:22 pm

  62. Yep, FlashBuilder update problem regarding the VerifyError: Error #1014.
    Here’s how you fix it: http://www.flexbrasilia.com.br/blog/2012/05/flash-builder-verifyerror-error-1014/

    Daniel

    16 May 12 at 10:54 pm

Leave a Reply