Android Beacon 库在一个 Android 4.4 设备上运行良好,但在另一个设备上运行不佳
Android Beacon Library works well on one Android 4.4 device, but not another
更新:我尝试了一种更直接的方法(参见下面的编辑 3),该方法导致手表上的信标缺少数据。
非工作设备的详细信息。
智能手表(通用)列为支持蓝牙 4.0
MTK6572芯片组
型号 EC720(似乎有很多变体)
Android4.4.2
内核:3.4.67 chendalin-Z87-HD3 #1 2014 年 12 月 27 日
内部版本号:H82D.SMARTWATCH.OC4.0.20141447
自定义构建版本:1419655453
我正在使用相同的 Radius Networks Tag 信标测试相同的应用程序。在这个测试中,我在我的设备附近有相同的 4 个信标。
设备 1 是 Nexus 7 (2013),我还没有更新到 Android L,它是 运行ning 4.4.4
设备 2 是一款通用智能手表,在 MTK6572 上 运行ning android 4.4.2。规格将其列为具有蓝牙 4.0
当我 运行 我的测试应用程序使用 Android 信标库时,Nexus 会报告信标,但智能手表不会。它似乎检测到它们,但是,我在 logcat 中看到条目,例如:D/BluetoothAdapter:onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-60。这些消息似乎通常在 BeaconParser 未设置为读取正确类型的信标时显示,但在我的情况下,我很确定这不是问题,因为 nexus 看到具有完全相同代码的信标。
这两个设备的日志输出看起来非常不同,我开始怀疑 android 是否以某种方式为手表构建,因为 BLE 支持被禁用或堆栈不完整。我仔细检查了蓝牙是否已打开,还想注意手表具有应用程序权限管理,我将其设置为 "Always Allow" 以获得应用程序请求的所有权限。
这里是 logcat 来自智能手表的部分:
02-03 19:40:40.393 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ This consumer is not bound. binding: com.mapcushion.android.mapcushionpingl.Scan@41c7d2c0
02-03 19:40:40.435 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ consumer count is now:1
...
02-03 19:40:40.617 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ beaconService version 2.1 is starting up
02-03 19:40:40.638 2620-2620/com.mapcushion.android.mapcushionpingl I/CycledLeScanner﹕ This is not Android 5.0. We are using old scanning APIs
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/ModelSpecificDistanceCalculator﹕ Finding best distance calculator for 4.4.2,KOT49H,EC720,alps
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/ModelSpecificDistanceCalculator﹕ Finding best distance calculator for 4.4.2,KOT49H,EC720,alps
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.646 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.646 2620-2620/com.mapcushion.android.mapcushionpingl W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default
02-03 19:40:40.648 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ No org.altbeacon.beacon.SimulatedScanData class exists.
02-03 19:40:40.649 2620-2620/com.mapcushion.android.mapcushionpingl D/ActivityThread﹕ SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@41cbbec8 className=org.altbeacon.beacon.service.BeaconService packageName=com.mapcushion.android.mapcushionpingl intent=null}
02-03 19:40:40.650 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ binding
02-03 19:40:40.656 2620-2620/com.mapcushion.android.mapcushionpingl D/ActivityThread﹕ SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@41cbbec8 intent=Intent { cmp=com.mapcushion.android.mapcushionpingl/org.altbeacon.beacon.service.BeaconService }}
02-03 19:40:40.723 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x552ed2b8) (w:256, h:240, f:1)
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl I/MaliEGL﹕ [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl I/MaliEGL﹕ [Mali]max_allowed_dequeued_buffers=3
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ close handle(0x552ed2b8) (w:256 h:240 f:1)
02-03 19:40:40.733 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x553ec108) (w:256, h:240, f:1)
02-03 19:40:40.735 2620-2620/com.mapcushion.android.mapcushionpingl D/OpenGLRenderer﹕ Enabling debug mode 0
02-03 19:40:40.737 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x5542c8a8) (w:768, h:768, f:1)
02-03 19:40:40.741 2620-2620/com.mapcushion.android.mapcushionpingl W/MALI﹕ MTK_AUX_isMTKFormat:168: int MTK_AUX_isMTKFormat(ANativeWindowBuffer_t*): format=1
02-03 19:40:40.743 2620-2620/com.mapcushion.android.mapcushionpingl D/OpenGLRenderer﹕ setViewport 240x240 <0x553ec690>
02-03 19:40:40.745 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ we have a connection to the service now
02-03 19:40:40.747 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ callback packageName: com.mapcushion.android.mapcushionpingl
02-03 19:40:40.747 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ This consumer is already bound
...
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ start ranging received
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Currently ranging 1 regions.
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ start called
02-03 19:40:40.828 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ starting a new scan cycle
02-03 19:40:40.829 2620-2620/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ isEnabled
02-03 19:40:40.834 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ starting a new bluetooth le scan
02-03 19:40:40.835 2620-2620/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ startLeScan(): null
02-03 19:40:40.874 2620-2633/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=1
02-03 19:40:40.879 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
02-03 19:40:40.880 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Scan started
02-03 19:40:40.880 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Set scan periods called with 1100, 0 Background mode must have changed.
02-03 19:40:40.881 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ We are not in the background. Cancelling wakeup alarm
02-03 19:40:40.881 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ cancel wakeup alarm: null
02-03 19:40:41.084 2620-2634/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-45
02-03 19:40:41.084 2620-2634/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mHandler = new android.os.Handler();
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setDebug(true);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(" m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
sendBeacons();
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
System.out.println("------- didRangeBeacons!!!!");
iBeacons = beacons;
System.out.println("------ num:: " + iBeacons.size());
/*
for(Beacon iBeacon : iBeacons) {
Log.i("Beacon", "found \nProxUUID: " + iBeacon.getId1()
+ "\ntx: " + Integer.toString(iBeacon.getTxPower())
+ "\nmanu: " + Integer.toString(iBeacon.getManufacturer())
+ "\ndistance: " + Double.toString(iBeacon.getDistance())
+ "\nRSSI:" + Integer.toString(iBeacon.getRssi())
+ "\nTxPow:" + Integer.toString(iBeacon.getTxPower())
+ "\nBeacon type code:" + Double.toString(iBeacon.getBeaconTypeCode())
+ "\n------------------------------------------------");
}
*/
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("briansbeacons", null, null, null));
} catch(RemoteException e) {
e.printStackTrace();
}
beaconManager.bind(this);
}
编辑 1:
添加更具体的日志条目以尝试显示信标检测的差异:我删除了除一个信标之外的所有信标,我注意到工作设备通过 UUID 识别信标,非工作设备不是。但是我在工作设备的日志中找不到任何对 Device=E5:E0:20:CF:63:32 的引用。
Nexus 7(工作):
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ beacon detected multiple times in scan cycle :id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ beacon detected :id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ looking for ranging region matches for this beacon
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ matches ranging region: id1: null id2: null id3: null
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/RangeState﹕ adding id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101 to existing range for: org.altbeacon.beacon.service.RangedBeacon@41eb5380
02-02 23:48:14.915 10727-10738/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
02-02 23:48:14.915 10727-10759/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:48:14.915 10727-10759/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
智能手表(不工作):
02-02 23:46:52.598 3351-3364/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-31
02-02 23:46:52.599 3351-3364/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
02-02 23:46:52.600 3351-3364/com.mapcushion.android.mapcushionpingl D/BluetoothDevice﹕ mAddress: E5:E0:20:CF:63:32
02-02 23:46:52.603 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:52.603 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:52.605 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:53.432 3351-3351/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Waiting to stop scan cycle for another 98 milliseconds
02-02 23:46:53.531 3351-3351/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Done with scan cycle
02-02 23:46:53.531 3351-3351/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Calling ranging callback
我注意到的另一件事是,在非工作设备中,对 BeaconService 的唯一引用如下:
02-02 23:46:52.364 3351-3351/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Calling ranging callback
02-02 23:46:52.364 3351-3351/com.mapcushion.android.mapcushionpingl D/Callback﹕ attempting callback via intent: ComponentInfo{com.mapcushion.android.mapcushionpingl/org.altbeacon.beacon.BeaconIntentProcessor}
而在工作设备中,信标的大部分日志记录似乎来自 class...
编辑 - 更新 2:
回应 David 关于 MAC 地址的问题
以下代码:
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
System.out.println("------- didRangeBeacons!!!!");
iBeacons = beacons;
System.out.println("------ num:: " + iBeacons.size());
for(Beacon iBeacon : iBeacons) {
Log.i("Beacon", "\n------------------------------------------------");
Log.d(TAG, "Mac address is: "+iBeacon.getBluetoothAddress());
Log.i("Beacon", "\n------------------------------------------------");
}
}
});
在工作的 Nexus 7 上制作:
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------- didRangeBeacons!!!!
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------ num:: 1
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/Beacon﹕ ------------------------------------------------
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl D/RangingActivity﹕ Mac address is: E5:E0:20:CF:63:32
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/Beacon﹕ ------------------------------------------------
在智能手表上:
02-03 19:40:46.671 2620-2671/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------- didRangeBeacons!!!!
02-03 19:40:46.671 2620-2671/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------ num:: 0
因此没有任何设备被 BeaconManager(或底层 android API)"seen" 作为信标,但它确实识别具有相同 MAC 地址的信标行:
02-03 19:40:46.486 2620-2633/com.mapcushion.android.mapcushionpingl D/BluetoothDevice﹕ mAddress: E5:E0:20:CF:63:32
编辑 3:
我决定退后一步,尝试使用 android 蓝牙 API 直接查询信标。
基本上我只是想输出返回的字节,看看为什么信标没有被识别。对于同一个信标,输出看起来完全不同,只有前两个字节有智能手表看到的信标数据,而 nexus 7 有 30 个字节的数据。
我尝试更改 SCAN_TIME 到目前为止没有效果。手表收不到数据是不是读不到ble包?
我使用了以下代码:
private static final long SCAN_TIME = 5000;
boolean mScanning = false;
private void scanLeDevice(final boolean enable) {
Log.i(null, "Inside scanLeDevice");
Log.i(null, "scan time is: " + SCAN_TIME);
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
Log.i(null, "Calling stopLeScan");
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}, SCAN_TIME);
mScanning = true;
Log.i(null, "Calling startLeScan");
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i(null, "INSIDE ONLESCAN");
//DO MY WORK
Log.i(null, "scanned record: " + scanRecord.length);
int startByte = 2;
boolean patternFound = false;
for(int i=0; i<scanRecord.length; i++) {
Log.i(null, "byte " + i + ": " + scanRecord[i]);
}
while (startByte <= 5) {
Log.i(null, "scanned record: " + scanRecord.length);
Log.i(null, "Identifier check: " + ((int) scanRecord[startByte + 2] & 0xff) + " == " + 0x02);
Log.i(null, "Length of data : " + ((int) scanRecord[startByte + 3] & 0xff) + "==" + (0x15));
//Log.i(null, " iBeacon Identifier: " + (scanRecord[startByte + 2] & 0xff));
if (((int) scanRecord[startByte + 2] & 0xff) == 0x02 && //Identifies an iBeacon
((int) scanRecord[startByte + 3] & 0xff) == 0x15) { //Identifies correct data length
patternFound = true;
break;
}
startByte++;
}
if (patternFound) {
//Convert to hex String
byte[] uuidBytes = new byte[16];
System.arraycopy(scanRecord, startByte+4, uuidBytes, 0, 16);
String hexString = bytesToHex(uuidBytes);
//Here is your UUID
String uuid = hexString.substring(0,8) + "-" +
hexString.substring(8,12) + "-" +
hexString.substring(12,16) + "-" +
hexString.substring(16,20) + "-" +
hexString.substring(20,32);
//Here is your Major value
int major = (scanRecord[startByte+20] & 0xff) * 0x100 + (scanRecord[startByte+21] & 0xff);
//Here is your Minor value
int minor = (scanRecord[startByte+22] & 0xff) * 0x100 + (scanRecord[startByte+23] & 0xff);
System.out.println("-------------output------ : " + uuid + " maj: " + major + " min: " + minor );
}
}
});
}
};
}
这是输出:
nexus 7(工作):
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ INSIDE ONLESCAN
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 0: 2
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 1: 1
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 2: 6
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 3: 26
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 4: -1
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 5: 76
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 6: 0
02-03 22:50:43.821 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 7: 2
02-03 22:50:43.821 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 8: 21
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 9: 47
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 10: 35
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 11: 68
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 12: 84
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 13: -49
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 14: 109
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 15: 74
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 16: 15
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 17: -83
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 18: -14
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 19: -12
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 20: -111
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 21: 27
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 22: -87
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 23: -1
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 24: -90
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 25: 0
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 26: 4
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 27: 0
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 28: 101
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 29: -76
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 30: 0
... (all 0's)
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 61: 0
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 255 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 76==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 76 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 2==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 2 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 21==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/System.out﹕ -------------output------ : 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 maj: 4 min: 101
02-03 22:50:43.912 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
智能手表(不工作):
2-03 22:53:37.374 6177-6189/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-46
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ INSIDE ONLESCAN
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 0: 2
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 1: 1
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 2: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 3: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 4: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 5: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 6: 0
... (all 0's)
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 61: 0
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.643 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
02-03 22:53:37.643 6177-6177/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ stopLeScan()
02-03 22:53:37.743 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
02-03 22:53:37.743 6177-6177/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ stopLeScan()
由于您通过 Nexus 7 确认信标的 Mac 地址为 E5:E0:20:CF:63:32,并且您看到手表将其广告读取为:
0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
而 Nexus 7 将其读取为非常不同的字节序列:
02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
我不得不得出结论,手表没有正确读取 BLE 制造商的广告——它在两个字节后截断了它们。
问题可能出在 MTK6572 ROM、硬件或两者协同工作的方式上。为了其他人,可能值得记录完整的手表配置。
更新:我尝试了一种更直接的方法(参见下面的编辑 3),该方法导致手表上的信标缺少数据。
非工作设备的详细信息。 智能手表(通用)列为支持蓝牙 4.0 MTK6572芯片组 型号 EC720(似乎有很多变体) Android4.4.2 内核:3.4.67 chendalin-Z87-HD3 #1 2014 年 12 月 27 日 内部版本号:H82D.SMARTWATCH.OC4.0.20141447 自定义构建版本:1419655453
我正在使用相同的 Radius Networks Tag 信标测试相同的应用程序。在这个测试中,我在我的设备附近有相同的 4 个信标。
设备 1 是 Nexus 7 (2013),我还没有更新到 Android L,它是 运行ning 4.4.4
设备 2 是一款通用智能手表,在 MTK6572 上 运行ning android 4.4.2。规格将其列为具有蓝牙 4.0
当我 运行 我的测试应用程序使用 Android 信标库时,Nexus 会报告信标,但智能手表不会。它似乎检测到它们,但是,我在 logcat 中看到条目,例如:D/BluetoothAdapter:onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-60。这些消息似乎通常在 BeaconParser 未设置为读取正确类型的信标时显示,但在我的情况下,我很确定这不是问题,因为 nexus 看到具有完全相同代码的信标。
这两个设备的日志输出看起来非常不同,我开始怀疑 android 是否以某种方式为手表构建,因为 BLE 支持被禁用或堆栈不完整。我仔细检查了蓝牙是否已打开,还想注意手表具有应用程序权限管理,我将其设置为 "Always Allow" 以获得应用程序请求的所有权限。
这里是 logcat 来自智能手表的部分:
02-03 19:40:40.393 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ This consumer is not bound. binding: com.mapcushion.android.mapcushionpingl.Scan@41c7d2c0
02-03 19:40:40.435 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ consumer count is now:1
...
02-03 19:40:40.617 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ beaconService version 2.1 is starting up
02-03 19:40:40.638 2620-2620/com.mapcushion.android.mapcushionpingl I/CycledLeScanner﹕ This is not Android 5.0. We are using old scanning APIs
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/ModelSpecificDistanceCalculator﹕ Finding best distance calculator for 4.4.2,KOT49H,EC720,alps
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/ModelSpecificDistanceCalculator﹕ Finding best distance calculator for 4.4.2,KOT49H,EC720,alps
02-03 19:40:40.645 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 4;KOT49H;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.646 2620-2620/com.mapcushion.android.mapcushionpingl D/AndroidModel﹕ Score is 0 for LGE;Nexus 5;LPV79;4.4.2 compared to alps;EC720;KOT49H;4.4.2
02-03 19:40:40.646 2620-2620/com.mapcushion.android.mapcushionpingl W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device. Using default
02-03 19:40:40.648 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ No org.altbeacon.beacon.SimulatedScanData class exists.
02-03 19:40:40.649 2620-2620/com.mapcushion.android.mapcushionpingl D/ActivityThread﹕ SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@41cbbec8 className=org.altbeacon.beacon.service.BeaconService packageName=com.mapcushion.android.mapcushionpingl intent=null}
02-03 19:40:40.650 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ binding
02-03 19:40:40.656 2620-2620/com.mapcushion.android.mapcushionpingl D/ActivityThread﹕ SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@41cbbec8 intent=Intent { cmp=com.mapcushion.android.mapcushionpingl/org.altbeacon.beacon.service.BeaconService }}
02-03 19:40:40.723 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x552ed2b8) (w:256, h:240, f:1)
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl I/MaliEGL﹕ [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl I/MaliEGL﹕ [Mali]max_allowed_dequeued_buffers=3
02-03 19:40:40.725 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ close handle(0x552ed2b8) (w:256 h:240 f:1)
02-03 19:40:40.733 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x553ec108) (w:256, h:240, f:1)
02-03 19:40:40.735 2620-2620/com.mapcushion.android.mapcushionpingl D/OpenGLRenderer﹕ Enabling debug mode 0
02-03 19:40:40.737 2620-2620/com.mapcushion.android.mapcushionpingl D/GraphicBuffer﹕ create handle(0x5542c8a8) (w:768, h:768, f:1)
02-03 19:40:40.741 2620-2620/com.mapcushion.android.mapcushionpingl W/MALI﹕ MTK_AUX_isMTKFormat:168: int MTK_AUX_isMTKFormat(ANativeWindowBuffer_t*): format=1
02-03 19:40:40.743 2620-2620/com.mapcushion.android.mapcushionpingl D/OpenGLRenderer﹕ setViewport 240x240 <0x553ec690>
02-03 19:40:40.745 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ we have a connection to the service now
02-03 19:40:40.747 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ callback packageName: com.mapcushion.android.mapcushionpingl
02-03 19:40:40.747 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconManager﹕ This consumer is already bound
...
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl I/BeaconService﹕ start ranging received
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Currently ranging 1 regions.
02-03 19:40:40.814 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ start called
02-03 19:40:40.828 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ starting a new scan cycle
02-03 19:40:40.829 2620-2620/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ isEnabled
02-03 19:40:40.834 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ starting a new bluetooth le scan
02-03 19:40:40.835 2620-2620/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ startLeScan(): null
02-03 19:40:40.874 2620-2633/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=1
02-03 19:40:40.879 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
02-03 19:40:40.880 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Scan started
02-03 19:40:40.880 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Set scan periods called with 1100, 0 Background mode must have changed.
02-03 19:40:40.881 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ We are not in the background. Cancelling wakeup alarm
02-03 19:40:40.881 2620-2620/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ cancel wakeup alarm: null
02-03 19:40:41.084 2620-2634/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-45
02-03 19:40:41.084 2620-2634/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mHandler = new android.os.Handler();
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.setDebug(true);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout(" m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
sendBeacons();
}
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
System.out.println("------- didRangeBeacons!!!!");
iBeacons = beacons;
System.out.println("------ num:: " + iBeacons.size());
/*
for(Beacon iBeacon : iBeacons) {
Log.i("Beacon", "found \nProxUUID: " + iBeacon.getId1()
+ "\ntx: " + Integer.toString(iBeacon.getTxPower())
+ "\nmanu: " + Integer.toString(iBeacon.getManufacturer())
+ "\ndistance: " + Double.toString(iBeacon.getDistance())
+ "\nRSSI:" + Integer.toString(iBeacon.getRssi())
+ "\nTxPow:" + Integer.toString(iBeacon.getTxPower())
+ "\nBeacon type code:" + Double.toString(iBeacon.getBeaconTypeCode())
+ "\n------------------------------------------------");
}
*/
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("briansbeacons", null, null, null));
} catch(RemoteException e) {
e.printStackTrace();
}
beaconManager.bind(this);
}
编辑 1:
添加更具体的日志条目以尝试显示信标检测的差异:我删除了除一个信标之外的所有信标,我注意到工作设备通过 UUID 识别信标,非工作设备不是。但是我在工作设备的日志中找不到任何对 Device=E5:E0:20:CF:63:32 的引用。
Nexus 7(工作):
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ beacon detected multiple times in scan cycle :id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ beacon detected :id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ looking for ranging region matches for this beacon
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ matches ranging region: id1: null id2: null id3: null
02-02 23:48:14.795 10727-10751/com.mapcushion.android.mapcushionpingl D/RangeState﹕ adding id1: 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6 id2: 4 id3: 101 to existing range for: org.altbeacon.beacon.service.RangedBeacon@41eb5380
02-02 23:48:14.915 10727-10738/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
02-02 23:48:14.915 10727-10759/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:48:14.915 10727-10759/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
智能手表(不工作):
02-02 23:46:52.598 3351-3364/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-31
02-02 23:46:52.599 3351-3364/com.mapcushion.android.mapcushionpingl D/CycledLeScannerForJellyBeanMr2﹕ got record
02-02 23:46:52.600 3351-3364/com.mapcushion.android.mapcushionpingl D/BluetoothDevice﹕ mAddress: E5:E0:20:CF:63:32
02-02 23:46:52.603 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:52.603 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:52.605 3351-3383/com.mapcushion.android.mapcushionpingl D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15. The bytes I see are: 0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
02-02 23:46:53.432 3351-3351/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Waiting to stop scan cycle for another 98 milliseconds
02-02 23:46:53.531 3351-3351/com.mapcushion.android.mapcushionpingl D/CycledLeScanner﹕ Done with scan cycle
02-02 23:46:53.531 3351-3351/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Calling ranging callback
我注意到的另一件事是,在非工作设备中,对 BeaconService 的唯一引用如下:
02-02 23:46:52.364 3351-3351/com.mapcushion.android.mapcushionpingl D/BeaconService﹕ Calling ranging callback
02-02 23:46:52.364 3351-3351/com.mapcushion.android.mapcushionpingl D/Callback﹕ attempting callback via intent: ComponentInfo{com.mapcushion.android.mapcushionpingl/org.altbeacon.beacon.BeaconIntentProcessor}
而在工作设备中,信标的大部分日志记录似乎来自 class...
编辑 - 更新 2:
回应 David 关于 MAC 地址的问题
以下代码:
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
System.out.println("------- didRangeBeacons!!!!");
iBeacons = beacons;
System.out.println("------ num:: " + iBeacons.size());
for(Beacon iBeacon : iBeacons) {
Log.i("Beacon", "\n------------------------------------------------");
Log.d(TAG, "Mac address is: "+iBeacon.getBluetoothAddress());
Log.i("Beacon", "\n------------------------------------------------");
}
}
});
在工作的 Nexus 7 上制作:
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------- didRangeBeacons!!!!
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------ num:: 1
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/Beacon﹕ ------------------------------------------------
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl D/RangingActivity﹕ Mac address is: E5:E0:20:CF:63:32
02-03 19:44:57.200 3192-3438/com.mapcushion.android.mapcushionpingl I/Beacon﹕ ------------------------------------------------
在智能手表上:
02-03 19:40:46.671 2620-2671/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------- didRangeBeacons!!!!
02-03 19:40:46.671 2620-2671/com.mapcushion.android.mapcushionpingl I/System.out﹕ ------ num:: 0
因此没有任何设备被 BeaconManager(或底层 android API)"seen" 作为信标,但它确实识别具有相同 MAC 地址的信标行:
02-03 19:40:46.486 2620-2633/com.mapcushion.android.mapcushionpingl D/BluetoothDevice﹕ mAddress: E5:E0:20:CF:63:32
编辑 3:
我决定退后一步,尝试使用 android 蓝牙 API 直接查询信标。
基本上我只是想输出返回的字节,看看为什么信标没有被识别。对于同一个信标,输出看起来完全不同,只有前两个字节有智能手表看到的信标数据,而 nexus 7 有 30 个字节的数据。
我尝试更改 SCAN_TIME 到目前为止没有效果。手表收不到数据是不是读不到ble包?
我使用了以下代码:
private static final long SCAN_TIME = 5000;
boolean mScanning = false;
private void scanLeDevice(final boolean enable) {
Log.i(null, "Inside scanLeDevice");
Log.i(null, "scan time is: " + SCAN_TIME);
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mScanning = false;
Log.i(null, "Calling stopLeScan");
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}, SCAN_TIME);
mScanning = true;
Log.i(null, "Calling startLeScan");
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
mScanning = false;
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, int rssi,
final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i(null, "INSIDE ONLESCAN");
//DO MY WORK
Log.i(null, "scanned record: " + scanRecord.length);
int startByte = 2;
boolean patternFound = false;
for(int i=0; i<scanRecord.length; i++) {
Log.i(null, "byte " + i + ": " + scanRecord[i]);
}
while (startByte <= 5) {
Log.i(null, "scanned record: " + scanRecord.length);
Log.i(null, "Identifier check: " + ((int) scanRecord[startByte + 2] & 0xff) + " == " + 0x02);
Log.i(null, "Length of data : " + ((int) scanRecord[startByte + 3] & 0xff) + "==" + (0x15));
//Log.i(null, " iBeacon Identifier: " + (scanRecord[startByte + 2] & 0xff));
if (((int) scanRecord[startByte + 2] & 0xff) == 0x02 && //Identifies an iBeacon
((int) scanRecord[startByte + 3] & 0xff) == 0x15) { //Identifies correct data length
patternFound = true;
break;
}
startByte++;
}
if (patternFound) {
//Convert to hex String
byte[] uuidBytes = new byte[16];
System.arraycopy(scanRecord, startByte+4, uuidBytes, 0, 16);
String hexString = bytesToHex(uuidBytes);
//Here is your UUID
String uuid = hexString.substring(0,8) + "-" +
hexString.substring(8,12) + "-" +
hexString.substring(12,16) + "-" +
hexString.substring(16,20) + "-" +
hexString.substring(20,32);
//Here is your Major value
int major = (scanRecord[startByte+20] & 0xff) * 0x100 + (scanRecord[startByte+21] & 0xff);
//Here is your Minor value
int minor = (scanRecord[startByte+22] & 0xff) * 0x100 + (scanRecord[startByte+23] & 0xff);
System.out.println("-------------output------ : " + uuid + " maj: " + major + " min: " + minor );
}
}
});
}
};
}
这是输出:
nexus 7(工作):
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ INSIDE ONLESCAN
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 0: 2
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 1: 1
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 2: 6
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 3: 26
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 4: -1
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 5: 76
02-03 22:50:43.811 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 6: 0
02-03 22:50:43.821 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 7: 2
02-03 22:50:43.821 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 8: 21
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 9: 47
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 10: 35
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 11: 68
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 12: 84
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 13: -49
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 14: 109
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 15: 74
02-03 22:50:43.831 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 16: 15
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 17: -83
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 18: -14
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 19: -12
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 20: -111
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 21: 27
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 22: -87
02-03 22:50:43.841 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 23: -1
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 24: -90
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 25: 0
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 26: 4
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 27: 0
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 28: 101
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 29: -76
02-03 22:50:43.851 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 30: 0
... (all 0's)
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ byte 61: 0
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 255 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 76==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 76 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 2==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 2 == 2
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 21==21
02-03 22:50:43.882 7303-7303/com.mapcushion.android.mapcushionpingl I/System.out﹕ -------------output------ : 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6 maj: 4 min: 101
02-03 22:50:43.912 7303-7303/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
智能手表(不工作):
2-03 22:53:37.374 6177-6189/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ onScanResult() - Device=E5:E0:20:CF:63:32 RSSI=-46
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ INSIDE ONLESCAN
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 0: 2
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 1: 1
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 2: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 3: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 4: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 5: 0
02-03 22:53:37.376 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 6: 0
... (all 0's)
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ byte 61: 0
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ scanned record: 62
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Identifier check: 0 == 2
02-03 22:53:37.378 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Length of data : 0==21
02-03 22:53:37.643 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
02-03 22:53:37.643 6177-6177/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ stopLeScan()
02-03 22:53:37.743 6177-6177/com.mapcushion.android.mapcushionpingl I/﹕ Calling stopLeScan
02-03 22:53:37.743 6177-6177/com.mapcushion.android.mapcushionpingl D/BluetoothAdapter﹕ stopLeScan()
由于您通过 Nexus 7 确认信标的 Mac 地址为 E5:E0:20:CF:63:32,并且您看到手表将其广告读取为:
0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
而 Nexus 7 将其读取为非常不同的字节序列:
02011a0bff4c0009060102c0a801130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
我不得不得出结论,手表没有正确读取 BLE 制造商的广告——它在两个字节后截断了它们。
问题可能出在 MTK6572 ROM、硬件或两者协同工作的方式上。为了其他人,可能值得记录完整的手表配置。