周辺Beaconを取得するWearアプリを追
加してローンチするまで
2016.07.21 potatotips #31
自己紹介
Kaori Ikada @Origami inc.
モバイルアプリエンジニア
基本的にikamon みたいなアカウントで動き回っている
やりたかったこと
ウェアラブルデバイスでのiBeacon の感度がどんなもんか
単純にwear アプリ作ってみたかった
携帯ラボでの検証風景
作ったもの
dongriさんのiBeaconFinder wear版
PlayStoreで配布中
https://play.google.com/store/apps/details?
id=at.dongri.android.ibeaconfinder
ソース: https://github.com/dongri/iBeaconFinder
構成
handheld がなくてもウェアラブル端末だけで動くように
(handheld とmessaging があるわけではない)
開発
Android Studioでwear アプリを追加
File > New > New Module...
Android Wear Module を追加
実装1
altbeacon を入れる
compile 'org.altbeacon:android-beacon-library:2.7'
おまじない
private static final String IBEACON_FORMAT =
"m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24";
beaconManager を作成し、Activityとbind
mBeaconManager =
BeaconManager.getInstanceForApplication(this);
mBeaconManager.getBeaconParsers()
.add(new BeaconParser().setBeaconLayout(IBEACON_FORMAT)
mBeaconManager.bind(this);
実装2
モニタ開始
mBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
try {
// 近くにbeaconが見つかったのでranging開始
mBeaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
}
// 略
});
mRegion = new Region("at.dongri.ibeaconfinder.regionid",
null, null, null);
// モニタ開始
mBeaconManager.startMonitoringBeaconsInRegion(mRegion);
実装3
ranging できたものを受け取る
mBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(
Collection<Beacon> collection,
       Region region) {
// 受け取った beacon たちの情報を出力
// major: beacon.getId2().toString()
// minor: beacon.getId3().toString()
// Distance: beacon.getDistance()
// RSSI: beacon.getRssi()
}
});
周辺beaconとれなくてハマる
ほぼ同じコードなのにエラーで動かない
当たり前だけど、本体でBlueTooth/LOCATION関連のパーミッ
ション取得済みでも、アプリケーション単体で動かすなら
wearだけでパーミッションを設定する必要があった
できた
使用端末:Huawei Watch
Android 6.0.1
アプリを公開する準備
:app build.gradle
wearApp project(':wear')
wear プロジェクトを本体アプリと紐付けることで、wearable デバ
イスとのペアリング時にインストールしてくれる
感想
思ったよりwatchの感度よかった
watchにも連打で開発者オプション有効があってアガった
We are hiring!
https://www.wantedly.com/companies/origami/projects

周辺beaconを取得するwearアプリを追加してローンチするまで