Adobe
製品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
その他の製品一覧
ソリューション
デジタルマーケティング
デジタルメディア
教育
金融機関
Web Experience Management
その他のソリューション
ラーニング サポート ダウンロード 会社情報
ご購入
アドビストア 安心のサポート& サービス
アカデミックストア 学生、教職員、個人向け
アドビライセンスストア 中小企業向け
ボリュームライセンスについて 企業、教育機関、官公庁向け
販売パートナー
キャンペーン情報
検索
 
情報 サインイン
ようこそ、 さん カート 注文状況 マイアカウント
マイアカウント
注文状況
アカウント情報の変更
コミュニケーションの設定を変更
サインアウト
サインインの目的 お客様のアカウントや体験版ダウンロード、製品の拡張機能、コミュニティエリアへのアクセスなどを管理するため
Adobe
製品 セクション ご購入   検索  
ソリューション 会社情報
サポート ラーニング
サインイン サインアウト 注文状況 マイアカウント
先行予約の提供開始予定日Date. 商品が発送されるまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。 先行予約の提供開始予定日Date. ダウンロードの準備が整うまで、クレジットカードには課金されません。提供開始の予定日は変更される場合があります。
個数:
ご購入には学生・教職員個人版の購入資格の確認が必要です。
小計
カートの中身を見る
Adobe Developer Connection / Adobe AIRデベロッパーセンター /

Exploring the new file capabilities in Adobe AIR 2

著者 Christian Cantrell

Christian Cantrell
  • blogs.adobe.com/cantrell

Created

17 November 2009

ページ ツール

Facebookでシェア
Twitterでツイート
LinkedInでシェア
ブックマーク
印刷

タグ

必要条件

この記事に必要な予備知識

This article is intended for developers who are comfortable with ActionScript 3 and who have at least a basic understanding of TCP sockets.

ユーザーレベル

中級

必要な製品

  • Adobe AIR

One of the biggest advantages of running an AIR desktop application over a browser-based web application is the richness of functionality that comes with installing an application on your desktop. For example, AIR applications can create notifications, change the dock or system tray icon, and, of course, access the file system.

AIR 1.0 provided a very rich set of file APIs that enabled developers to read and write from the file system; move, copy, and delete files; traverse directories; open native file picker dialog boxes; and more. AIR 1.1 added the spaceAvailable property to the File class in order to enable developers to determine how much space is available on a given volume. AIR 2 expands the file APIs even further by adding the ability to:

  • Open files with their default registered application.
  • Flag files as "downloaded" so that some operating systems will caution users before opening them for the first time.
  • Get notified of mounted and unmounted storage volumes, and query those volumes for information.

This article covers the following topics:

  • Launching a file's default application
  • Flagging a file as downloaded
  • Listening for mounted volumes and accessing volume information
  • Sample application: FileTile

Launching a file's default application

AIR 2 adds the function openWithDefaultApplication to the File class. Calling openWithDefaultApplication on a file opens whichever application the operating system associates with that file, and then activates that application. For example, if the file instance points to a Microsoft Word document, calling openWithDefaultApplication will cause Microsoft Word to open and load the referenced file, or calling openWithDefaultApplication on an image might cause that image to be opened with Photoshop or other default application for images.

You should be aware of the following caveats before using the openWithDefaultApplication function:

  • You cannot open an application without referencing a file that is associated with that application.
  • The openWithDefaultApplication function can only be called from code running inside the application sandbox. If it's called by code running outside the application sandbox, a security error is thrown.
  • The openWithDefaultApplication function does not provide any means to communicate with the launched process after it's open. If you need to launch an external process and subsequently communicate with it, see the new NativeProcess APIs in AIR 2.
  • The AIR runtime does not verify the file before it is passed to the associated application, so if the file has an incorrect extension, it's possible that the application that is launched to handle it will not be able to read it.
  • It is not possible to use the openWithDefaultApplication function to launch executables directly. In order to preserve the platform-independent nature of Adobe AIR applications, you must use the new NativeProcess APIs in AIR 2, combined with a native installer, to launch executables from AIR.
  • If you call openWithDefaultApplication on a file that does not have a default application associated with it, a runtime error is thrown. Be sure to catch this error in your code and handle it gracefully if your application allows for this scenario.
  • If you call openWithDefaultApplication on a directory, it will open in your default file explorer application (Finder, Windows Explorer, Nautilus, and so on).

The following code shows how to open a Keynote presentation on Mac OS X:

var presentation:File = File.documentsDirectory.resolvePath("Presentations/MAX_2009.key"); presentation.openWithDefaultApplication();
openWithDefaultApplication is platform-independent as well as user-independent, since it opens files with whichever application is associated with the referenced file type. For example, calling openWithDefaultApplication on an MP3 file might open iTunes on Mac OS X, Windows Media on Windows, or VLC on Linux.

Flagging a file as downloaded

AIR 2 also adds to the File class the downloaded property, which enables AIR applications to specify whether a file was downloaded over a network. On some operating systems, setting this property to true will result in the user getting a security notification the first time he or she tries to open the file. For example, when a user opens a file that was downloaded through Safari on Mac OS X, the operating system displays a dialog box that requires the user's confirmation before the file is actually opened. When saving files in an AIR application that were downloaded over a network (for example, in an FTP client), setting this property to true is considered a best practice.

Note: Files that are downloaded through the FileReference.download method are automatically marked as downloaded.

The downloaded property only has an effect on Windows XP SP2 and later (including Vista and Windows 7), and on Mac OS 10.5 (Leopard) and later. Currently, Linux does not support this property; therefore, setting it in an application running on Linux will have no effect.

The following code shows setting the downloaded property to true on a file that was downloaded from the network and saved locally:

var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.BINARY; loader.addEventListener(Event.COMPLETE, function(e:Event):void { var air:File = File.userDirectory.resolvePath("Downloads/AdobeAIR.dmg"); var fs:FileStream = new FileStream(); fs.open(air, FileMode.WRITE); fs.writeBytes(loader.data); fs.close(); air.downloaded = true; }); var req:URLRequest = new URLRequest("http://airdownload.adobe.com/air/mac/download/latest/AdobeAIR.dmg"); loader.load(req);

Listening for mounted volumes and accessing volume information

The final addition to the file system APIs in AIR 2 provides the ability to listen for the mounting and unmounting of storage volumes, and to query storage volumes for information. For example, if your application needs to know when a USB flash drive has been plugged in, a network drive has been mounted or a digital camera has been connected, you can listen for the StorageVolumeChangeEvent and have your application react accordingly.

To be notified of the mounting and unmounting of storage volumes, add an event listener to the StorageVolumeInfo singleton instance like this:

StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount); StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);

The StorageVolumeChangeEvent contains a reference to the StorageVolume that was just mounted (the storageVolume property is null if the StorageVolumeChangeEvent was fired in response to a volume being unmounted). The StorageVolume class provides several properties containing information on the storage volume such as:

  • fileSystemType
  • isRemovable
  • isWritable
  • drive
  • name
  • rootDirectory

Note: The drive property refers to the drive letter on Windows, and is null on Mac. The name property refers to the volume name on both Mac and Windows.

You don't always have to listen for the StorageVolumeChangeEvent to get information about mounted storage volumes; the getStorageVolumes function on the StorageVolumeInfo class returns a vector of mounted storage volumes. The following code demonstrates getting a list of all mounted storage volumes:

var volumes:Vector. = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes(); for each (var volume:StorageVolume in volumes) { trace(volume.name, volume.rootDirectory.nativePath); }

FileTile: The new AIR 2 file system APIs in action

FileTile, shown in Figure 1, is a sample application I wrote to demonstrate the new AIR 2 file system APIs. It's a utility for browsing storage volumes like flash drives and digital cameras which expose themselves as storage volumes. You can install FileTile from Adobe Labs, or download the full source code from Google Code.

The FileTile application
Figure 1. The FileTile application

Where to go from here

This article covered all the new file capabilities in the AIR 2. For more information, refer to:

  • Demonstration of the new storage volume APIs in AIR 2
  • FileTile on Google Code
  • FileTile sample application in the Adobe AIR Developer Center

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Resolving DNS records in Adobe AIR 2
  • Using drag-and-drop support of remote files in Adobe AIR 2
  • Retrieving a list of network interfaces in Adobe AIR 2
  • Using the Salesbuilder sample application
  • Reducing CPU usage in Adobe AIR
  • Building multilingual Flex applications on Adobe AIR
  • Building an XML viewer on Adobe AIR with Flex
  • Creating a socket server in Adobe AIR 2
  • User experience considerations with SQLite operations
  • Creating accessible Adobe AIR applications with the Flex SDK

製品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • モバイルアプリ
  • Photoshop
  • Touch Apps

ソリューション

  • デジタルマーケティング
  • コンテンツオーサリング
  • Web Experience Management

業種別ソリューション

  • 教育
  • 金融機関

サポート

  • ヘルプ&サポート
  • 注文と返品
  • ダウンロードに関するヘルプ
  • ユーザー登録に関するヘルプ

ラーニング

  • ADC: Adobe Developer Center
  • Adobe TV
  • Design Magazine
  • Photoshop Magazine
  • Focus In

ご購入方法

  • アドビストア
  • アカデミックストア
  • アドビライセンスストア
  • ボリュームライセンスについて
  • 販売パートナー
  • キャンペーン情報

ダウンロード

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

会社情報

  • プレスルーム
  • パートナープログラム
  • 企業の社会的責任(英語)
  • 採用情報
  • 投資家の皆様へ(英語)
  • イベント&セミナー
  • Legal(英語)
  • セキュリティ
  • お問い合わせ
国・地域および言語の選択 日本(変更)
国・地域および言語の選択 閉じる

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.

利用条件 | プライバシーポリシーとCookie (更新)

Reviewed by TRUSTe: site privacy statement