Windows ストアアプリから使かえるセンサーAPIとデバイスAPI

Post on 20-Aug-2015

8.226 views 3 download

Transcript of Windows ストアアプリから使かえるセンサーAPIとデバイスAPI

Windows ストア アプリから使かえるセンサーAPIと

デバイス API

日本マイクロソフト株式会社

デベロッパーエクスペリエンス&エバンジェリズム統括本部

物江 修

Windows ストア アプリ~ Windows 8 の新しい UI 環境で動作するアプリ ~

既存のスキルを活かした開発~ さまざまな言語で開発が可能~

JavaScript

C#, VB

C, C++

HTML5

XAML

開発言語 UI 記述スキルセット

+

+

Web

.net

Native

HTML5 + JavaScript Windows ストア アプリの構造

ホストプロセス

オペレーティングシステム

アプリ

API

JavaScript

ネイティブ API

直接呼び出し (Compiled)

開発に使用する技術~ Web 標準とネイティブライブラリ~

WWAHost.exe Internet Explorer のスーパーセット

HTML5

CSS3(Trident)

Web 標準

WinJSWindows Library for

JavaScript

JavaScript

アプリのフレームワーク

JavaScript

Windows 8 の機能にアクセス

JavaScript

Windows ランタイムが提供するハードウェアリソース API

• Device• Bluetooth

• GenericAttributeProfile

• Rfcomm

• Geolocation• Geofencing

• HumanInterfaceDevice

• PointOfService• BarcodeScanner

• MagneticStripeReader

• Portable

• Printers

• SmartCards

• Sms

• Windows• Media

• Networking

• Storage

• Device

• Usb

• WiFiDirect

• Sensors

• Sensors• Accelerometer

• Compass

• Gyrometer

• Inclinometer

• LightSensor

• Magnetometer

• OrientationSensor

• SimpleOrientation

Sensor

Windows ストア アプリから接続可能なデバイスの種類~ 2種類に大別 ~

内部搭載機器 外部接続機器(周辺機器)

Windows Store Apps

・・・

・・・

アプリからデバイスにアクセスするには~ appxmanifest ファイルでデバイスアクセスの許可~

外部接続機器の許可設定~ appxmanifest ファイルに手動で記述~

<Capabilities><Capability Name=“internetClient” /><!-- HID デバイスの情報を設定 --><m2:DeviceCapability Name="humaninterfacedevice">

<m2:Device Id="any"><m2:Function Type="usage:0001 0010" />

</m2:Device></m2:DeviceCapability>

</Capabilities>

Package/Capabilities下にデバイス情報を記述

参考 : How to specify device capabilities in a package manifest (Windows Runtime apps)http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn263092.aspx

デバイスへのアクセスの方法~「目的」に合わせたそれぞれの専用クラスを使う~

var capt = Windows.Media.Capture; //カメラ(撮影)用 UI のインスタンスを生成var captUI = new capt.CameraCaptureUI(); //写真撮影メソッドを実行し、撮影した画像の処理は非同期でおこなうcaptUI.captureFileAsync(capt.CameraCaptureUIMode.photo).done( function (file) {

//img タグを追加し src 属性に撮影した写真を指定var img = document.createElement("img"); img.src = URL.createObjectURL(file); document.getElementById("content").appendChild(img); img.style.position = "absolute";

}); });

例) 写真撮影

周辺機器へのアクセス~機器を検出列挙し、ID からインスタンスを生成~

var deviceInfo = Windows.Devices.Enumeration.DeviceInformation;var deviceClass = Windows.Devices.Enumeration.DeviceClass;//デバイスの一覧を取得deviceInfo.findAllAsync(deviceClass.all).done(function (deviceInformations) {

//Promise にセットされたコールバックルーチンの引数に一覧がセットされるvar length = deviceInformations.length;var deviceEntry = null;for (var i = 0; i < length; i++) {deviceEntry = deviceInformations[i]console.log(“name:” + deviceEntry.name);console.log(“id:” + deviceEntry.id);

}});

まとめ

Windows Store Apps

+

参考

デバイスとITの架け橋http://blogs.msdn.com/b/hirosho/