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

15
Windows ストア アプリから 使かえるセンサーAPIと デバイス API 日本マイクロソフト株式会社 デベロッパーエクスペリエンス&エバンジェリズム統括本部 物江 修

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

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

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

デバイス API

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

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

物江 修

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

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

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

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

JavaScript

C#, VB

C, C++

HTML5

XAML

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

+

+

Web

.net

Native

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

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

ホストプロセス

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

アプリ

API

JavaScript

ネイティブ API

直接呼び出し (Compiled)

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

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

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

HTML5

CSS3(Trident)

Web 標準

WinJSWindows Library for

JavaScript

JavaScript

アプリのフレームワーク

JavaScript

Windows 8 の機能にアクセス

JavaScript

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

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

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

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

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

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

Windows Store Apps

・・・

・・・

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

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

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

外部接続機器の許可設定~ 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

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

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

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";

}); });

例) 写真撮影

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

周辺機器へのアクセス~機器を検出列挙し、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);

}});

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

まとめ

Windows Store Apps

+

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

参考

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

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