I think push notifications are a must nowadays for mobile apps. Awesome in one word! Maybe just because I could not implement them until now without native extensions.
Looked around for already made solution and found two: one free here from Afterisk and one paid here from Distriqt (this also includes many other cool extensions and for iOS too).
But since I was gonna do it my way, that means not using foreign code :), I started reading all kinds of tutorials about GCM starting from here. I’ve managed to do it in native Android, but not quite do it in a native extension for air (adobe native extensions tutorials here). My problem was some permissions and the way they had to be included in the manifest file. So I gave up since the deadline for my project was right around the corner and followed Afterisk’s tutorial and code.
First of all you need the Project Number (not the Project ID) from the Google APIs Console where you enabled GCM. You will need this when you’ll want to register a device for notifications.
From the API Access tab you will need to create keys for those who want to send notifications to subscribed clients (for example your java sever, or your php file.. ) and you also can restrict access so no one else is using your account to send notifications to those clients. If you are curios to test it find this attached native android sources here. Notice the permissions needed and entered in the manifest. (just replace YOUR PROJECT NUMBER FROM THE GOOGLE APIS CONSOLE with your project number). How to test it? After you receive a registration ID from GCM server you enter it here in the first field. The sources for this php file are here.
Afterwards you will want to use this awesome thing in your air app. Download the latest files from Afterisk and follow their instructions. Flash Builder test project is here.
For the extension to work in debug mode you have to add .debug in 3 places – see the manifest file from the Flash Builder project.
<id>ro.ileo.gcm</id> <permission android:name="air.ro.ileo.gcm.debug.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="air.ro.ileo.gcm.debug.permission.C2D_MESSAGE" /> <category android:name="air.ro.ileo.gcm.debug" />
When you release your application you will have to delete the .debug appearances from the manifest file.
So the extension works, you receive the notifications, Afterisk is great, now the final touch would be changing the icons that appear on top of your phone in the notifications bar. Download this zip file from over here, unzip it, change your icons in that folder and run generateANE.bat. You will have to have adt in your path. Voila! Simple isn’t it?
PS: one more thing, if you try to unregister, the GCM servers have a delay until they really unregister you for good