Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center / Native extensions for Adobe AIR /

Notification native extension sample

by Daniel Koestler

Daniel Koestler
  • blogs.adobe.com/koestler

Content

  • The ActionScript Library
  • The Application Descriptor
  • Where to go from here

Created

4 October 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR 3 Android iOS mobile

Requirements

Prerequisite knowledge

Familiarity with Flash Builder 4.6, ActionScript 3, and AIR/Flex.

User level

Intermediate

Required products

  • Adobe AIR 3

Sample files

  • notification.zip

Note: By clicking the download link for any source examples on this page, you acknowledge that you have read and agree to the Adobe AIR SDK License Agreement. These files are considered Sample Code.

Note: Adobe recommends using the next version of Flash Builder for developing native extensions for Adobe AIR. Sign up now to get access to the prerelease of Flash Builder 4.6.

Adobe AIR has allowed application developers to extend the features of the runtime with a set of tools known as native extensions. By using native extensions, your applications can access all of the features of your target platform, even if the runtime itself doesn't have built-in support. This example expands AIR by allowing you to create notifications in AIR apps you deploy to Android and iOS. These notifications appear as any other system notification. You can customize the notification type, text, actions to be taken when the notification is dispatched.

The attached ZIP file contains:

  • Notification.ane: The Notification native extension that you have to include in your Flash Builder project.
  • NotificationSample.fxp: A simple Flash Builder 4.6 project that shows you how to dispatch notifications on Android and iOS.
  • The folder asdocs: This contains documentation on using this native extension.

The ActionScript Library

Notification objects are created in AS3, and dispatched by a NotificationManager.

You can start dispatching notifications by coding the following:

private var notificationManager:NotificationManager protected function notifyUser():void { if ( !this.notificationManager ) { try { this.notificationManager = new NotificationManager(); } catch (ae:ArgumentError) { trace("The notification native extension has no support for this platform."); return; } } var n:Notification = new Notification(); n.tickerText = this.tickerText.text; n.title = this.notificationTitle.text; n.body = this.notificationBody.text; this.notificationManager.notifyUser("MY_NOTIFICATION_TYPE",n); }

The notifyUser() function dispatches the notification using the native extension. On Android, the notification appears in the notification drawer (accessible by sliding the drawer down from the top of the screen). iOS handles notifications slightly differently: if the application is running when the notification is dispatched, you won't receive a pop-up; if the application is running in the background (multitasking by using a background API), you'll receive the pop-up dialog box when the notification is dispatched.

Notification objects and their behavior are configurable:

  • actionData: Used for specifying custom actions taken when the notification is addressed by the user
  • actionLabel
  • alertPolicy: A value of NotificationAlertPolicy, specifying whether the user should be alerted every time this notification appears, or only the first time
  • body
  • cancelOnSelect
  • iconType: Pick from the Icons available in the NotificationIconType, which are the same as the system's default notification icons
  • tickerText: The text that appears at the top of the Android window shade when the notification first appears
  • title
  • vibrate

Add an eventListener to the NotificationManager to receive an event when a notification has been addressed by the user. It's recommended you do this during the initialization of the NotificationManager instance. For example, code the following in a creationComplete handler of an s:View object:

protected function view1_creationCompleteHandler(event:FlexEvent):void { try { this.notificationManager = new NotificationManager(); } catch (ae:ArgumentError) { trace("The notification native extension has no support for this platform."); return; } this.notificationManager.addEventListener(NotificationEvent.NOTIFICATION_ACTION,onNotificationActionEvent); } private function onNotificationActionEvent(ne:NotificationEvent):void { trace("Notification action received. Type: " + ne.actionData); }

You'll then receive a NotificationEvent.NOTIFICATION_ACTION when the notification is selected by the user (Android), or the action button is tapped (iOS). The ne.actionData will be set to the actionData value you set on the notification.

View the asdocs/index.html file contained in the sample to learn more about notifications and the NotificationManager.

The Application Descriptor

If you're deploying to Android, be sure to specify this additional permission in the manifestAdditions tag of your application descriptor XML file:

<application> <service android:name="com.adobe.ep.localnotifications.LocalNotificationIntentService"/> </application>

This allows your application to be opened when the user taps the notification in the Android window shade (the notification area). No additional permissions are required for iOS applications.

Where to go from here

For more information about developing native extensions for Adobe AIR, see:

  • Extending Adobe AIR
  • Developing Native Extensions for Adobe AIR
  • Adobe native extension samples

For more information about using a native extension in an AIR application, see:

  • Using native extensions for Adobe AIR

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Vibration native extension sample
  • Gyroscope native extension sample
  • NetworkInfo native extension sample

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement