Skip to content

Instantly share code, notes, and snippets.

@KazuyukiEguchi
Created December 6, 2013 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KazuyukiEguchi/7828733 to your computer and use it in GitHub Desktop.
Save KazuyukiEguchi/7828733 to your computer and use it in GitHub Desktop.
AndroidでiBeacon信号を受信してみよう ref: http://qiita.com/KazuyukiEguchi/items/2f6c439ae8faeb06d23f
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
mBluetoothAdapter.startLeScan(mLeScanCallback);
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,byte[] scanRecord) {
// デバイスが検出される度に呼び出されます。
});
};
if(scanRecord.length > 30)
{
if((scanRecord[5] == (byte)0x4c) && (scanRecord[6] == (byte)0x00) &&
(scanRecord[7] == (byte)0x02) && (scanRecord[8] == (byte)0x15))
{
String uuid = IntToHex2(scanRecord[9] & 0xff)
+ IntToHex2(scanRecord[10] & 0xff)
+ IntToHex2(scanRecord[11] & 0xff)
+ IntToHex2(scanRecord[12] & 0xff)
+ "-"
+ IntToHex2(scanRecord[13] & 0xff)
+ IntToHex2(scanRecord[14] & 0xff)
+ "-"
+ IntToHex2(scanRecord[15] & 0xff)
+ IntToHex2(scanRecord[16] & 0xff)
+ "-"
+ IntToHex2(scanRecord[17] & 0xff)
+ IntToHex2(scanRecord[18] & 0xff)
+ "-"
+ IntToHex2(scanRecord[19] & 0xff)
+ IntToHex2(scanRecord[20] & 0xff)
+ IntToHex2(scanRecord[21] & 0xff)
+ IntToHex2(scanRecord[22] & 0xff)
+ IntToHex2(scanRecord[23] & 0xff)
+ IntToHex2(scanRecord[24] & 0xff);
String major = IntToHex2(scanRecord[25] & 0xff) + IntToHex2(scanRecord[26] & 0xff);
String minor = IntToHex2(scanRecord[27] & 0xff) + IntToHex2(scanRecord[28] & 0xff);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment