The only free and fully functional Android GCM native extension for Adobe AIR

Overview

This tutorial is about native extension for Adobe AIR and GCM (Google Cloud Messaging) which is a free service provided by Google that allows messages to be pushed to devices of your app users. If anyone is interested in more information on how to create an Android app capable of reception of GCM messages please check out this article on Google dev portal: GCM Tutorial.

In the course of development of  a new social drawing app “Sketch Guess”, we wanted to add an ability for the server to notify players when important events occur in the game and display the appropriate view when the application resumes or restarts (the “fetch message payload after app just launched” capability is only implemented in our own solution so far). While there is an abundance of Adobe AIR native extensions for iOS, there was definitely a gap to be filled for Android applications.

The only way to proceed was to create our own extension which I’m going to provide here for download along with a fully functional example application and a set of instructions below.

The extension is made for Adobe SDK 4.6 + AIR SDK 3.1 . Although, I’m sure it’ll work with 4.5 and 3.0 or newer versions. My weapon of choice in developing Air things is Intellij 10 or 11, so I won’t be providing exact procedures to link to “.ane” when you setup the project since that varies from environment to environment.

Anyway, first things first. Please download the archive which contains extension and the example application from here. The package also contains APK which can be installed to any Android 2.2 +  right away and tested (it uses GCM sender ID of one of our test apps).

Actual extension “gcm.ane” is located in “ane/” folder and can’t be used right away for your own project (the usage can be seen in example application).

Compile and run example application

After downloading create a project for the example application in the IDE of your choice (Intellij, Flash Builder, Flash Develop, Flash CS) and use the following class as the main/application class:

“com.afterisk.gcmdemo.GCMExample” and the output swf file as “GCMExample.swf ” (I’m using ‘bin’ folder as output folder).

In dependencies of your project, specify a new library that includes “gcm.ane”. That should get rid of all the missing references application has. If you are using Flash Builder older than 4.6 or Intellij 10 you might want to duplicate gcm.ane and rename it into “gcm.swc” in order for the compiler to recognize the references.

Create a run configuration (to run on device) that uses the provided “gcm-air-app.xml” descriptor file, connect your device via USB and compile. That is really all that’s needed!

Use extension in your own application.

First you need to obtain your own Sender ID it’s on the lower part of your application page on Android Development Console. It looks like this:

GCM Sender ID

In order to obtain for your app you need to go here and follow Google’s instructions. Once that is done, replace the value of public static const GCM_SENDER_ID:String with your own senderID.

Now, insert the following part of provided application xml into your own application xml (things that need to be updated with your own data are highlighted):

<!-- Specify Android specific tags that get passed to AndroidManifest.xml file. -->

<!--[<span class="hiddenSpellError" pre="">CDATA</span>[-->

<!-- App receives GCM messages. -->

<!-- GCM connects to Google Services. -->

<!-- GCM requires a Google account. -->

<!-- Keeps the processor from sleeping when a message is received. -->

]]>

<!-- End of the schema for adding the android specific tags in AndroidManifest.xml file -->

Where you see “air.com.afterisk.gcmdemo” in descriptor xml you must update it with the ID you are using for the application and prepend it with “air.” (You need to do this because all AIR applications are added “air.” in front of the package name.)

Example of application id:

<id>com.mygreatcompany.myawsomeapp</id>

The references to that in GCM part of manifest should be:

<permission android:name=”air.com.mygreatcompany.myawsomeapp.permission.C2D_MESSAGE” android:protectionLevel=”signature” />
<uses-permission android:name=”air.com.mygreatcompany.myawsomeapp.permission.C2D_MESSAGE” />

….

<category android:name=”air.com.mygreatcompany.myawsomeapp” />

If you entered everything correctly you can create a run configuration and run the app on your device while using your own sender ID!

Sending and Receiving

There are certain parameters that this native extension expects to receive:

“title” – a title of message that shows in notification bar (optional).

“alert” – a message shown to users in notification bar, when notification is received and the application is either in the background or not running.

“type” – type of notification. You can put any string data into it, this parameter will be sent to client as a part of String typed message when application launches or resumes from notification.

“id” – same as “type,” another piece of data that is sent as part of String message (again, anything can be placed into it!).

Here is a PHP example showing construction of GCM payload (full class attached):


$message = array('title' => 'Sketch Guess', 'alert' => $user . ' created a new sketch!', 'type' => 'sketch_created', 'id' => $gameid);

$fields = array('registration_ids' => $registration_ids, 'data' => $message);

In AIR, if you trace your GCMEvent message property it will look something like this: “type: the_value_of_type_parameter,  id:  the-value_of_id_parameter”.

You can parse it however you like. Here is my example of the GCMEvent.MESSAGE “message” property parsing:


var pairs:Array = (message.split(","));
var space:RegExp = /"/g;
_notificationType = String(String(pairs[0]).split(":")[1]).replace(space, "");
_id = String(String(pairs[1]).split(":")[1]).replace(space, "");

Update:
This extension will send events wether the app is in the background or not to determine your app status use the following events, and handle GCM events apppropriately:


NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true); 

Based on the parameters of “id” or “type” you can now show an appropriate view to your users.

The example of fully working GCM messaging on Android can be seen in our new drawing game:

Click to view Sketch Guess, the social drawing game, implementation.

I hope the extension we created will help you with GCM messaging implementation.

Good luck!

Download

Again, here is GCM Extension and Example download link.

PHP Class to push messages to GCM service: GCM.php

GitHub address: https://github.com/AfteriskInc/AirGCM

Support Us

299 comments

  1. Pingback: First free Facebook Single Sign-On (SSO) Adobe AIR native extension for Android | Priorisk
  2. Eric

    i change icon in the res folder , now i want to rebuild ane, how to use ADT Tool to rebuild,have tutorial?
    sorry my english so bad.

  3. anderson

    VerifyError: Error #1014: Class com.afterisk.shared.ane.lib::GCMPushInterface could not be found. where is shared??!

  4. Berat

    I tried your ane on Galaxy S3(Android 4.1.2) it is registered succesfully, but when i tried it on Xperia Arc S(Android 2.3.4) it writes Registering but no effect after that. Events are not triggered. Do you know the reason?

    Thank you.

  5. Berat

    I read that you were busy and couldn’t add sound to ane. Did you add it for now? Or do you think make your project open source?

    Thanks

  6. ram

    SRY my text didn’t appear .
    What i mean that in our app.xml where we add permission to c2dm we have to add: android:name=”air.id.debug.permission.C2D_MESSAGE” android:protectionLevel=”signature”
    uses-permission android:name=”air.com.mygreatcompany.myawsomeapp.permission.C2D_MESSAGE”
    category android:name=”air.com.mygreatcompany.myawsomeapp”

    On release apk we should remove .debug

  7. Brad Patterson

    I do not get any Notifications at all. I have worked on this for hours, and have gone through the entire tutorial 3 times just to make sure I haven’t skipped anything.
    The app will register and send back a ResigrationID. I send a message out through php and google sends back a success:1, failure:0 in the return json.
    The device does nothing. No text in the _messageField, nothing on the device itself.
    I am using a Samsung Galaxy 10.1. I am sure the issue is something I am doing wrong, but for the life of me I can’t figure it out.
    Like I said, everything seems to work, but the actual Notification on the device.
    thanks

      • Brad Patterson

        the last output in LogCat is…
        GCMPushInterface Code: registered
        It looks like it registered.
        I am using my google API Project Number as the Sender ID, I could not find a sender ID anywhere and I found online that it is now Project Number. Compiling with Air 3.6.
        Google Cloud Messaging For Android is turned on in the Services.

      • afterisktech

        sender id is displayed in your google play publishing admin, when you’re looking at the app details you can click at “Services & APIs” and it will be displayed as “Linked sender id”.

      • Brad Patterson

        I have tried everything. I just don’t receive any notifications at all. Everything else seems to be working fine.
        Did a lot of searching and google uses project id not sender id.
        Does this app have to be installed through the google play for it to receive messages? or can it be installed like a normal debug apk through terminal? Is my problem not going through Google Play?

      • afterisktech

        it doesn’t have to be installed through google play, but it has to be registered on google play and you must use correct sender id and package name. its a common error to apply wrong package or id.

  8. Florian Matoflink

    Hi,
    As many people here, my GCMEvent.REGISTERED is never fired. I think i tried every solution in the previous comments so my manifest should be ok. I hope someone has an idea and I post my manifest.
    Thank you very much.
    ( air.TestMobile )

  9. John Clarkson

    Thank you, worked perfectly. I have one issue where the debug trace shows that I receive the Remote Notification on my Samsung S3 (Android 4.1.2) for *every* push that I send, but I do not always see the icon in the notification bar. Has anyone else had this problem?

    Aside: Our project is also used on desktop and iOS (with different ANE for remote notifications). Rather than using conditional compilation etc I created a default actionscript only version of the library.swf that just implements the GCMPushInterface and GCMEvent interfaces and compiled it into the ANE (e.g. the last part of this command: adt -package -target ane gcm.ane extension.xml -swc extension.swc -platform Android-ARM -C android . -platform default -C default library.swf). I found (painfully) that to package a default implementation for iOS I had to be using an AIR SDK later than 3.4.

  10. saint

    Hi, guys, respect for your great work.
    How about including sounds and vibration to the ANE… any thoughts about that?

  11. Pingback: AIR Native Extensions Collection
    • afterisktech

      this interface has capability to unregister, but it can’t unregister when you just uninstall. call unregister before they quit and re-register again on every app launch. thats how you can do it.

  12. moon

    hi:
    When I user this ane on motorola x911,It traces GCMRegistrar: registering sender 1012537563378 but Events are not triggered.When I add .debug after <permission android:name="air.MobileLHNOVA. It logs still GCMRegistrar: registering sender 1012537563378 ,no other messages , Do you know the reason ? Thank you!
    I use exzample apk it can get id from gcm,if i change my projectid and rebuild it ,it still says GCMRegistrar: registering sender 1012537563378

    • afterisktech

      try to see what your php (if you are using php) code says, see if delivery fails, see if you have any registered devices in your db (if you are using it), the sende you’re posting here. is it yours? i just checked the sender id you provided…it’s not ours…debug sender code.

      • ogy

        FATAL EXCEPTION: IntentService[GCMIntentService-DynamicSenderIds-1]
        java.lang.IllegalArgumentException
        at com.adobe.fre.FREContext.dispatchStatusEventAsync(Native Method)
        at com.afterisk.shared.android.gcm.GCMIntentService.onMessage(GCMIntentService.java:50)
        at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:154)
        at android.os.HandlerThread.run(HandlerThread.java:60)

      • ogy

        i have permission for this but still in logcat:
        Permission Denial: receiving Intent { act=com.google.android.c2dm.intent.RECEIVE cat=[air.com.mbroomstic] flg=0x10 (has extras) } to air.com.mbroomstic.debug requires air.com.mbroomstic.permission.C2D_MESSAGE due to sender com.google.android.gsf (uid 10040)
        still the notification is ok but without sound and if app is in background has fatal errror

      • ogy

        Can i make that the notification still come when the app is in background just like when the app is not running?

  13. temp89

    thanks sir for this amazing library
    but i don’t get any registration ID
    i’ve added .debug since i’m debugging
    but i get nothing
    what could be the problem?

    • afterisktech

      There could be a thousand reasons why it happens. You can start debugging by creating the new app (for testing) with the same package id and use the same sender id. if it works you need to find a reason in your own app.

  14. Stephan Müller

    hi there, first of all: thanks for the extension! unfortunately i’m having problems receiving push messages, using urban airship to deliver test messages (debug mode on).
    here’s what i did:
    1. obtained a sender id via google (157978887xxx – last three digits replaced with an x); note: i haven’t uploaded an APK to google before, i just created the entry for being able to enable GCM for it and getting the sender id.
    2. used the same code as yours
    3. changed permissions in application xml (my app package name is com.skizzo.redar), it looks like this: http://pastebin.com/XJ74gWQj
    the result is only the call of the function “register” (which is done after initializing the CGMPushInterface object), but there is nothing like “registrationID” in the response text, so the whole block in the end of the register function is not being called..
    thanks for your help!
    – stephan

  15. Skizzo

    Hi and first of all: Thanks for your extension! Unfortunately, I can’t get it to work. If it’s okay, I post the steps I did, and hope some of you gurus can help me! 🙂
    1. Added an app in the Google Developer Console (in my case, the only thing i really entered is the name of the app, which is “redar”). Since I simply want to test if GCM is working on my Android smartphone, I did not upload an .APK yet.
    2. Got myself a Sender ID (In my case, 157978887xxx, where x is a 1-digit-number I don’t want to publish here)
    3. Used the code you posted and used the obtained Sender ID as GCM_SENDER_ID.
    4. Edited my app xml (package id: com.skizzo.redar), it now looks like this (please see: http://pastebin.com/VSpn437G
    5. Registered on urbanairship.com
    6. Added an app on urbanairship.com, named “redar”, set the mode to debug mode.
    7. Added the GCM service, package name = “com.skizzo.redar”, API key = The same key I used for obtaining my Sender ID.
    8. Launched the app.
    In the function register(), I get the following response string:
    GCMRegistrar: registering sender 157978887xxx
    (x is again a 1-digit-number I don’t want to publish here)
    Since you’re checking the response for the index of “registrationID:” which can’t be found in the response, the functions handleRegistrationIDReceived etc. are not called. Furthermore, no GCMEvent event handler is ever called..
    Could you please help me? What am I doing wrong? Is it because I didn’t upload an APK? Could there be something wrong with the app xml?
    Thanks a mill!

  16. kimus

    Hi! The extension works well, I can get the “registrationId”, however, I need to send this Id to urban airship API (api/apids/), and they need a version 4 UUIDs (36 characters long) of this id…….. but the Id that I receive from your extension is really longer than 36 chars… any ideas ? thanks !

    • Skizzo

      how exactly would you send your registrationID (mine is 162 digits long) to urban airship? the function “handleRegistrationIDReceived” is empty except the comment..

      • kimus

        Thanks again for your Answer it helped me dig a little deepter. From what I understand now, UrbanAirship expect an “ApId” OF THEIR OWN in their back-end “api/apids” call. They probably bas this “APID” on the 162 digits registrationId given in the GCM SDK … This “APID” would actually be available only from the JavaLib they give to code a JavaClient. So, for now, my conclusion is that, for Android devices, if we are using UrbanAirship as a back-end service, we would need a NativeExtension for Air that exposes the UrbanAirship Java Lib.
        We can see here that the registrationId from GCM is a different property than the “APID”:
        http://docs.urbanairship.com/android-lib/reference/com/urbanairship/push/PushManager.html

      • afterisktech

        yes, like i said they have their own system, a mediator between platform and your client…so yeah either use the extension for airship or just make your own backend. Its rather simple. The php example is included with my blog post.

      • Skizzo

        thanks kimus, but does that subsequently mean that there is no way to use the extension provided in this tutorial in combination with urban airship and android?

  17. kimus

    From what I understand, yes, we can’t use this extension if we need to connect with UrbanAirship. It’s really disapointing cause I installed and used your extension for iOS and it worked perfectly.
    I did contact support for UrbanAirship, and they confirm that we need to user their Native Javalib extension. 😦 😦

      • afterisktech

        unfortunatelly this extension is written for GCM not for urban airship service…urban airship requires a different sdk to use…you may also try and use your own backend like we and a lot of other people do, it’s not that complicated…the only problem is you’ll need to have your own hosting…

  18. airmobileAndrius

    Hello, thanks allot for an amazing library 😉 Some of you experienced an issue that app crashes if notification comes when app is running. I’m wondering if anyone solved that problem, if so how? Looks like I did everything correctly because I can receive notifications without problems when app isn’t running.
    The other small issue is that notifications come without sound. Is it somehow possible to make the default sound to play when notification is received?
    Thanks allot in advance 🙂

  19. Jerry Hamby

    I hope someone can help, I’m not getting any data when my app receives the COMING_FROM_NOTIFICATION event.
    I can get the GCM token OK, but when the Push service I’m using sends a message, the data is empty.
    Have you send this issue or have suggests?

      • Jerry Hamby

        Here is the problem I’m seeing when I get a notification:
        D/c2dmBdcastRcvr(3934): Broadcast receiver started!!!!!
        D/c2dmBdcastRcvr(3934): bitmap null
        W/GTalkService(760): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=air.pushpop (has extras) }
        I/air.pushpop(3934): Push notification is supported
        I/air.pushpop(3934): [PushNotification Error] cannot parse the params string
        (There is no data for the ANE to parse)

        Why is this happening?

  20. raduanastase

    I used the demo with my own GCM sender ID with my nexus s (4.2.2) and it worked fine, i then tried it with my Samsung Galaxy Tab 2 (4.0.3) and nothing. After that i tried it with my friend’s Samsung Galaxy S 2 (4.0.4) and again, nothing (it stops at “registering sender …”). I also mention that i tried all of these devices with the original demo code and GCM sender ID and obtained the same results.

    I tried putting “air.” in front of my app id but again, nothing.

    I put here the xml http://pastie.org/8336087 .

    Maybe, when you have time, you could tell me what I’m doing wrong.

    Thanks

      • raduanastase

        You were right.
        Although it is mentioned in the comments something about debug version I didn’t thought that I should build a release version for testing. So that was my problem, on Nexus S it worked also in debug mode, but on other devices it worked only in release build. So my advice to anyone who tries to communicate with GCM with this ANE or other ANEs, please, for the love of Android, work on the release build 🙂

  21. Jerry Hamby

    I’m doing a test with my push notification provider and have an issue with the ANE:
    I send the provider this JSON object:
    { “title”: “this is title”, “id”: “This is ID”, “type”: “This is type”, “message”: “message goes here”, “alert”: “This is a test alert” }

    The response object shown by your ANE:
    GCM IntentService class: com.afterisk.shared.android.gcm.GCMIntentService
    Acquiring wakelock
    V/GCMBaseIntentService(8958): Intent service name: GCMIntentService-DynamicSenderIds-2
    I/air.air.pushpop(8958): GCMPushInterface Status: type:This is type,id:This is ID
    mHandleMessage e = [Event type=”GCMEvent.MESSAGE” bubbles=false cancelable=false eventPhase=2]
    mHandleMessage e.message = type:This is type,id:This is ID

    Why am I only receiving “type” and “id” and not any of the other properties?
    Need help please!

    • afterisktech

      hmm…hard to say, but if the part is received and part is missing, then i’d say data wasn’t parsed right. check your input? for example i see you’re using “ instead of regular double or single quotations…that’s just my guess…

  22. Amani S

    Your ANE works like a charm thank you.
    but there is an error that i’m facing
    when i turn off the mobile device and turn it on an alert pops up claiming that there was a problem and the app has stopped working.
    i’m sure its from this ANE, because i removed the ANE, turned off and on the mobile device no error, and even tried the app with the ANE on other devices same error..
    any suggestions? or is anyone facing the same thing?

    • afterisktech

      Maybe your device is running out of ram and it causes it to force-close the app. Not sure, since I’ve never seen such an issue (if anything it was just dropping my app all together, but without messaging of any kind)

  23. SteveCohen34

    Hi, i try for 2 days to make it work but it don’t want… I see i’m not only to have this problem but i’m the only to don’t find how to fix it…

    Nothing append after “Registring device with GCM…”

    To be sure to forget nothing in app.xml i paste your and modify for my app: http://pastebin.com/kzkJ4Byz

    To test it i use flash builder and actionscript but it pretty similary, see my View : http://pastebin.com/JPnZNyQe

    All listeners are registered but Registered is never called…

    Do you know why ?

    ps: i use t-pad with android 4.0.4, i tried your app and work fine. I don’t know what i forgot…

  24. Victor Yew

    Hi, I have been scratching my head for a couple of days while all I get from the trace is “GCMRegistrar: registering sender XXXXXXX….” when I call this function _gcmi.register(GCM_SENDER_ID). Please help.

  25. Huggles

    Hey there!

    After quite a while I finally got your ANE working. (In a very basic form tho!)

    Now when I send a push notification, it instantly pops up on my device and all. The text, title etc can be set. But the Icon that pops with the push notification shows as the “question pencilmark” you used for one of your apps (and is referred to in the example code).

    Where do I change this? 🙂

    Thanks in advance!

  26. Luis Miguel

    Hi,

    First of all, I want to say that the title of this blog entry says exactly what this is, this is the only ANE that I’ve found (after making a profound search on the Web) that works with the GCM and it’s completely free! So, I must say thanks a lot for sharing it with everyone and good job.

    I, myself, have been struggling for a couple of weeks making my own ANE for this but I had problems exporting the Google APIs libraries required for the GCM to work within the Android native project. I’m not an Android developer myself so after trying (and failing) for sometime I decided to quit and search for an existing ANE that would help do the job, and guess what, this was the only one I found.

    Now, the reason I’m writing this is the following;
    I understand that your ANE was thought to get notifications specificly for your SketchGuess app, that’s why you are only sending the “type” and the “id” variables of the payload from the Android side to the extension through the StatusEvent.
    The thing is that in the application we are developing, we are interested in getting the hole payload or at least all the custom variables that we may add to it when the notification is sent from the server (this is what we are currently doing with iOS notifications so I supposed it’s possible).

    Now, I far as I understand, in order to achieve this behavior, the ANE should be (lightly) changed. Would you be willing to make a custom build of the ANE with such changes? I know this is asking a lot but you have no idea how incredibly helpful this would be.

    If this wouldn’t be possible, is the are a chance you could give me some advice on how to successfully export the native Android project to have it include the GCM libraries?

    I don’t usually ask for these kind of help but these are times of real need!

    Thank you beforehand!

    PS: I really enjoyed that LD28 entry I had some trouble understanding the use of the different elements at the beginning but in the Kongregate version is kind of neat, the game’s challenging but really good. We had the chance to participate too and this is what came out http://www.ludumdare.com/compo/ludum-dare-28/?action=preview&uid=31847

    • afterisktech

      Well the idea behind GCM payload plugins (unless catered to something particular) is that you would create value pairs, assign them to one field and then parse in client, because they come as a bunch of strings anyway, the payload does not support objects or datatypes other then string. That is true not only for this plugin but for anything that uses push GCM/APN etc.

  27. Hakko

    Hi! Thanks for making this publicly available for everyone to use! I’ve created a test app in Flash CC, ran the debug version on my phone. I also managed to get the php side working, and the messages are received when the app is active or running in the background. When the app is closed however, the messages don’t come in. No notification at all.

    Does the app need to be in the Play Store for Google to know which phone to target or something? I think I’m missing something here..

      • Hakko

        Thanks for the swift reply.
        I’ve uploaded the app to G Play and published an Alpha version. But still no notifications when the application is closed..
        The app doesn’t fetch them when opening later on either. It does receive messages send when the app is opened.

        Logcat shows nothing

      • afterisktech

        No problem. Hmm…this is rather odd, and I don’t think I’ve encountered such issue or question here before. The only thing i can think of is that you unregister the id before quitting. By app opened you mean app is active but in the background?

      • Hakko

        Alright. I’ve looked at the trace outputs and it shows no unregistration before closing the application. When I open the app again it registers automatically, after which it does say the device was already registered.

        By app opened I meant open in the foreground. The app UI is visible, and I can see the message coming in in the textfield. The text shown is:

        GCMPushInterface Status: type:null,id:null
        GCMPushInterface Code: foregroundMessage
        GCMPushInterface Status: type:null,id:null
        GCMPushInterface Code: message
        app is in the background: adding GCM app invoke listener
        app was invoked by gcm notification

        OH wait. scratch that. Just closed the app, and tried sending the message and I got a notification! /
        hmm.. but only one time. On the second try no notification was received. I’ll just go on and try some things. It worked once, so I guess the code should be good right..?

      • Hakko

        Ok, I’m getting the notifications now. I had to install the app from the Play store, not the APK directly I guess.
        Only thing now is that it’s a quiet notification. No sound, no vibrations, no led. Is this by design, or do I need to add something to the php code?

        thanks!

      • afterisktech

        It doesn’t create notifications when app is in foreground. no point right? What it does instead is sending “foreground message” event directly to air client. So you can still handle if someone or your backend sends you something.

      • afterisktech

        sound and vibrations are set to default of the phone current state. the LED was never considered. if you need to update your icon you can unpack jar and replace it then repack it. (see comments, people did it before)

  28. Claus

    Hi guys, although problems have been numerous and solutions probably too, I just came across some strange behaviour when testing this ANE in both debug and release modes.
    In debug build, I had to use the API key for server applications, which is a long string of numbers and letters e.g. AIzaLaNgeDadleR2014sAAdan89deRfoRAVGGILDt
    In release build, I, much to my surprise, had to use my project ID. Otherwise it would never get past the ‘Registering device with GCM’ message !
    Just to let you know if you run in to similar problems.
    If anyone can explain this, please, I am all ears !
    Cheers, CK

  29. Claus

    How about that sound and vibrations – has anyone got that working ? On both my devices, it is a completely quiet notification, eventhough they are both set up to play a sound and vibrate on notifications…
    And, as Ogy has mentioned, it crashes the app when it is in background on one of my devices running Android 4.0.3. On my HTC Desire, running Android 2.2, it works as it should (no sounds though).
    Here is a bit of the logcat:
    threadid=17: thread exiting with uncaught exception (group=0x4186c1f8)
    FATAL EXCEPTION: IntentService[GCMIntentService-DynamicSenderIds-2]
    java.lang.NullPointerException
    at com.afterisk.shared.android.gcm.GCMIntentService.isAppInForeground(GCMIntentService.java:123)
    at com.afterisk.shared.android.gcm.GCMIntentService.onMessage(GCMIntentService.java:63)
    at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.os.HandlerThread.run(HandlerThread.java:60)

    Cheers, CK

    • Claus

      So continuing down the troubleshooting path, line # 123, which apparently is failing, has the following code:
      ActivityManager activityManager = (ActivityManager)context.getSystemService(“activity”);
      Judging from the exception, it must mean that ‘context’ is null ? Could you add a check and return false from the isAppInForeground-method if context is null ?
      I honestly don’t know why it is failing on Android 4.3.7 and not on 2.2…
      Cheers, CK

    • afterisktech

      They work with default settings of the system, if you have sound there should be sound otherwise no, same for vibrations. Sorry, I did not have time more time to spend on it. It was a gesture of good will, then other things kick in. I provide reasonable support but some of it is just beyond reach.

      • Claus

        Hi, thank you for your swift reply. I fully understand that supporting this for all eternity simply is too much. I will try to debug this a little further and post my findings here. Good will indeed, it is much appreciated, rest assured. Thanks, cheers, CK

      • Claus

        Hi again, sorry it took a while… I read somewhere that waking an app with a notification required the app to register for this particular kind of behaviour in the OS on first run. This change in requirement was introduced in Android 3.1, which explains why it worked on my phone running v2.2 and not on my tablet running 4.0.3.
        Long story short, I added the flag so the app tells the OS to wake it even if it is stopped when a notification for the app is received. I also have fixed the null pointer exception (at least it seems so) as well as added default sound, led-light flashes and vibration upon notification. In our test suites it has worked well so far. Would you like to host the modified ANE ?
        Thanks again, cheers, CK

      • afterisktech

        Great job, mate! Thanks for helping out! unfortunately we can’t host it because that’ll require a thorough testing, but! we can link to it in the post, if you provide me with a URL and a short description of the updates you made (release notes).

  30. sudoplz

    Hey man, I’ve set up your ane, register just fine so far so good.
    When I send a (custom JSON) message from my push notification service (appcelerator cloud), eventhough I get a GCMEvent.MESSAGE dispatch, the message is type:null, id:null.
    The JSON I send is this: {
    “alert”: “Test alert”,
    “type”: “Test type”,
    “id”: “Test id”
    }
    What am I doing wrong?

      • sudoplz

        Hmm, but isn’t the whole point to just receive a JSON with those 3 things inside? “alert”,“type”,“id”? If it receives a JSON with those 3 inside what difference does it make where it comes from?
        Perhaps I need to add something more in my JSON?

      • afterisktech

        sory sudoplz, i can’t give support for json or the custom push notifications. something is wrong before it gets into the app, why? i don’t know. try and use test php chunk to debug. if that works turn to your service see how you compose the json string…

  31. T-Macintosh

    I can’t understand the “Compile and run example application” part.
    I get the error “VerifyError: Error #1014: Class com.afterisk.shared.ane.lib::GCMPushInterface could not be found.” and I think the main reason is this part.
    can you tell me more specifically?

      • sudoplz

        2 things you might want to double check T-Macintosh.
        1. That the ane itself is being transfered INTO the device (for example in intellij, I have to add the ane itself, onto the assets that WILL be transfered into the device, from the module settings)
        2. That you’ve set the into your app xml, which I believe you have.

        Most probably your ane is not transfered in your device, therefore you’ve got an issue on runtime!

  32. Fabrice

    Hi there. First of all, thanks for your ANE. You make my day !
    Everything works like a charm !
    Everything but vibration and sound.
    Claus told us on 27 march 2014 that he did it works with some modification of your ANE. Is there an open source version of your great work ?
    Before posting, i’ve tried integrating com.adobe.VIBRATION ANE and consequent … Checking all my phones parameters about notification sounds and vibration……. and so on…….
    I did’nt get any vibration nor sound. :’-(
    I’m very interrested by your java code on this project and if there is a link (of your original work or of Claus’s work), i’ll be happy to get it. 😉
    There is another project (http://myappsnippet.com/gcm/) with a very similar code… are you working on it ? if so, i’ll buy this ANE with more options…
    Best regards,

  33. Thiago Camargo

    Hi, I’ve used the ANE and it works fine, it’s really cool.
    However after adding the ANE my app is crashing when I try to run it in the simulator.
    As far as I’ve read online this happens because the ANE didn’t include the ‘default’ implementation.
    Is there a plan for that to be fixed or maybe the ANE source code made available so community could fix it?

  34. Rami

    Hey afterisktech,

    I am using your ane from last year and everything works fine but i need to add 2 new folders to android/res (drawable-xxhdpi and drawable-xxxhdpi). Can i add these two new folders ? do the icons added take effect on devices xxhdpi and xxxhdpi ?

    Plus the sizes of the icons in drawable-hdpi, drawable-ldpi, drawable-mdpi and drawable-xhdpi do not fit android forum example:

    for the folder drawable-mdpi your icon size is 24×24 however in the forum 48×48 is used. (baseline)
    for the folder drawable-hdpi your icon size is 36×36 however in the forum 72×72 is used.
    for the folder drawable-xdpi your icon size is 48×48 however in the forum 96×96 is used.

    for the folder drawable-ldpi, you normally don’t need to create custom assets at this size because Android effectively down-scales your HDPI assets by 1/2 to match the expected size.

    Find below Android forum about icon sizes:
    http://developer.android.com/design/style/iconography.html

    Thanks,

  35. N@ulet

    As I’m french, does anyone have an idea to make characters with accent (àéè…) appear in the “alert” field?

  36. Mike Cheung

    For Sound and Viberation, I solved by adding code to GCMIntentService.java

    Line 78
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_SOUND;

  37. Cellina

    Hi, @afterisktech
    I have worked for 1 day and can’t get the register id with trace the following result
    “GCMPushInterface: registered Status Listeners”
    “Registering device with GCM…” . This is my app.xml (http://pastebin.com/CJmgipda), please give me some hint, thank you!

Leave a reply to afterisktech Cancel reply