Androidの面白い仕組みの一つに Intent があります。Intent を使うことで、メールソフトやダイヤラー、カメラを起動することができます。
| droid.startIntent(uri) | Intentを起動する |
| droid.startIntentForResult(uri, callback) | Intentを起動して結果をcallbackで受け取る |
| droid.scanBarcode(callback, mode, show_help) | バーコードアプリを起動してバーコードを読み取る |
| scanQRCode(callback, show_help) | QRコードを読み取る |
| recognizeSpeech(callback, language) | 音声入力を行ってcallbackに文字列を返す |
droid.scanBarcode()のmodeにはAUTO/QR_CODE_MODE/ONE_D_MODE/DATA_MATRIX_MODEを指定します。QRコードを読むなら、droid.scanQRCode()メソッドを利用します。
以下、利用例です。
<h2>Mail/Tel</h2>
<div class="buttons">
<button class="func" onclick="TestSendMail()">Send Mail</button>
<button class="func" onclick="TestTel()">Call 117</button>
</div>
<script>
function TestSendMail() {
droid.startIntent("mailto:hoge@example.com?subject=About_jsWaffle&body=test");
}
function TestTel() {
droid.startIntent("tel:117");
}
</script>
<h2>Camera/Video</h2>
<div class="buttons">
<button class="func" onclick="TestCamera()">Camera</button>
<button class="func" onclick="TestVideo()">Video</button>
</div>
<script>
function TestCamera() {
droid.startIntentForResult(
"camera:/sdcard/hoge.jpg",
function(code){
droid.startIntent("file:/sdcard/hoge.jpg");
});
}
function TestVideo() {
droid.startIntentForResult(
"video:/sdcard/hoge.mpg",
function(code){
droid.startIntent("file:/sdcard/hoge.mpg");
});
}
</script>
カメラを起動するには、uriに「camera://***」のように書きます。***には、撮影した写真を保存するパスを記述します。
対応している uri は以下の通りです
| URL | 機能 |
| camera:ファイル名 | (写真用)カメラを起動 |
| video:ファイル名 | 動画レコーダーを起動 |
| http:アドレス(https) | Webブラウザの起動 |
| tel:電話番号 | ダイヤラーの起動 |
| sms:電話番号 | SMSの起動 |
| geo:緯度経度 | マップの起動 |
| mailto:メールアドレス | メーラーの起動 |
| file:ファイルパス | ファイルの起動(拡張子判別) |
| record: | ボイスレコーダーの起動 |
ちなみに、droid.startIntentForResult() で対応しているのは、camera/video のみです。