Created
December 6, 2013 17:26
-
-
Save KazuyukiEguchi/7828733 to your computer and use it in GitHub Desktop.
AndroidでiBeacon信号を受信してみよう ref: http://qiita.com/KazuyukiEguchi/items/2f6c439ae8faeb06d23f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.BLUETOOTH"/> | |
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final BluetoothManager bluetoothManager = | |
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); | |
mBluetoothAdapter = bluetoothManager.getAdapter(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mBluetoothAdapter.startLeScan(mLeScanCallback); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { | |
@Override | |
public void onLeScan(final BluetoothDevice device, int rssi,byte[] scanRecord) { | |
// デバイスが検出される度に呼び出されます。 | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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