Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy 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
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center / Native extensions for Adobe AIR /

Vibration native extension sample

by Adobe

Adobe logo

Content

  • The ActionScript library
  • Application usage
  • The Android native library
  • The iOS native library
  • Where to go from here

Created

21 September 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScriptAdobe AIR 3AndroidiOSmobilenative extensions
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Familiarity with building mobile apps on Adobe AIR, including familiarity with Objective C and Xcode, or Android development.

 

Required third-party products

  • Android SDK
  • iOS SDK 4
  • Xcode
  • Eclipse

User level

Intermediate

Required products

  • Adobe AIR 3

Sample files

  • Vibration.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.

The Vibration class is a native extension for Adobe AIR. It allows AIR application developers, from ActionScript, to use the vibration feature of an Android or iOS mobile device.

The attached ZIP file contains:

  • The ActionScript library in the directory VibrationActionScriptLibrary: This directory contains the Flash Builder project for creating the ActionScript side of the Vibration extension.
  • The Android native library in the directory VibrationAndroidLibrary: This directory contains an Eclipse project for creating the Android native side of the Vibration extension. To build the Eclipse project, first copy FlashRuntimeExtension.jar from <AIR_SDK>/lib/android/FlashRuntimeExtensions.jar to the directory VibrationAndroidLibrary\libs.
  • The iOS native library in the directory VibrationiOSLibrary: This directory contains an Xcode project for creating the iOS native side of the Vibration extension. To build the Xcode project, first copy FlashRuntimeExtension.h from <AIR_SDK>/include/FlashRuntimeExtensions.h to the directory
     VibrationiOSLibrary.
  • A directory called ReadyToUseExtension: This directory contains everything the AIR application developer needs to use the native extension: the ANE file, the SWC file, and a text file that contains the extension ID.
  • A directory called TestVibrationExtension: This directory contains a sample AIR application that uses the Vibration native extension.

The ActionScript library

The ActionScript library contains the Vibration class. The Vibration class provides the AIR application this public property and method:

  • public static function get isSupported(): Boolean
  • public function vibrate(duration:Number): void

The AIR application can create many instances of the Vibration class. However, the Vibration class creates only one ExtensionContext class instance that all the Vibration instances share.

Application usage

To use the Vibration extension, an AIR application does the following:

  • Checks if the extension is supported by calling isSupported.
  • Causes the device to vibrate by calling vibrate(), specifying the duration of the vibration in milliseconds as a parameter.

For example:

var vibe:Vibration; if (Vibration.isSupported) { vibe = new Vibration(); vibe.vibrate(2000); }

Android applications

For an Android application, include the Vibration permission in your application descriptor file:

Android Permission : <uses-permission android:name="android.permission.VIBRATE"/>

iOS applications

For an iOS application:

  • The isSupported property always returns true. On iOS devices, no native API is available to determine whether the vibration feature is supported.
  • The duration value passed to vibrate() is ignored. The device vibrates for a duration determined by iOS.

The Android native library

The Android native library is implemented in Java, using the native extension Java API. The native library includes the following classes:

  • VibrationExtension implements FREExtension
  • VibrationExtensionContext extends FREContext
  • VibrationSupportedFunction, VibrationInitNativeCode, and VibrationVibrateFunction each implement FREFunction

The native library also contains examples of using these FREObject methods:

  • getAsInt()
  • newObject()

In its initialization, the native library uses the getActivity() method of the FREContext class to get the application's Android Activity. Using the returned Activity, the initialization method, which is VibrationInitNativeCodeFunction.call(), gets the vibration service:

Activity a = vibExtContext.getActivity(); vibExtContext.androidVibrator = (Vibrator) a.getSystemService(Context.VIBRATOR_SERVICE);

Note: The call from the ActionScript side to ExtensionContext.createExtensionContext() must return before the native library can call methods of the object derived from the FREContext class. Therefore, the call vibExtContext.getActivity() occurs in the initialization function that the ActionScript side calls after the return from createExtensionContext(). The call to getActivity() cannot occur in the FREContext object constructor.

The iOS native library

The iOS native library is implemented in Objective C, using the native extension C API. The native library contains examples of these native extension C APIs:

  • The extension initializer and finalizer, using the signatures of FREInitializer() and FREFinalizer().
  • The context initializer and finalizer, using the signatures of FREContextInitializer() and FREContextFinalizer().
  • Native functions, using the signature of FREFunction(). The native functions are IsSupported(), InitNativeCode(), and VibrateDevice().
  • FRENewObjectFromBool()

The function VibrateDevice() calls the iOS API AudioServicesPlaySystemSound() to vibrate the device. However, if the device does not support vibration, this iOS API call does nothing.

Note: In the iOS native implementation, no initialization is necessary, and so the initialization native function, InitNativeCode(), does nothing. However, the function is necessary because the Android native implementation requires an initialization function. Therefore, to make the extension’s ActionScript interface the same for all native implementations, the iOS native implementation provides the stub.

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

More Like This

  • NetworkInfo native extension sample
  • Gyroscope native extension sample

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

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 © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement