private final ThreadLocal<ScanCallback> mScanCallback = new ThreadLocal<ScanCallback>() {
@Override
protected ScanCallback initialValue() {
return new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
ScanRecord btScanRecord = result.getScanRecord();
//Log.i(TAG,"new johoksdfjkhdfsj");//Not Called
if (btScanRecord != null) {
}
Connect();
//Log.i(TAG,"new johoksdfjkhdfsj");//Not Called
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
for (ScanResult sr : results) {
Log.i("ScanResult-Results", sr.toString());
//Log.i(TAG, sr.toString());//not called
}
}
@Override
public void onScanFailed(int errorCode) {
Log.e("Scan Failed", "Error Code: " + errorCode);
}
};
}
};
我只想要rssi,timestamp和mac-address,但我认为这段代码给了我一些其他字符串,如制造商详情,广告标志等。
答案 0 :(得分:0)
试试这个BLE Scan听众:
public BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// also get address using
// device.getAddress();
addDevice(device,rssi);
String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
Log.e("In h:m:s"," "+currentDateTimeString);
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
Log.e("In miliseconds"," "+ts);
}
});
}
};
我希望这项工作。