Bluetooth low energy android 没有给我一个真实地址只有空名称
Bluetooth low energy android doesn’t give me a real address only null name
谁能帮帮我?我想使用低功耗蓝牙扫描附近的设备,但是当我扫描它时,它给我随机地址,名称为 null 这是我的代码:
当我在两个 phone 上打开 BLE 广告时,我下载了一个名为 BLE 扫描仪的应用程序,之后我在我的应用程序上打开我的扫描,它给了我真实的地址,否则什么都没有发生,我的 phone 没有t 扫描任何 phone :(
public void scanBLEDevices(Boolean enable) {
final ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
Toast.makeText(BluetoothActivity.this, "result scan", Toast.LENGTH_SHORT).show();
BluetoothDevice device = result.getDevice();
String bluetoothAddressScanned = device.getAddress();
Toast.makeText(BluetoothActivity.this, bluetoothAddressScanned + " "+device.getName()+result.getRssi(), Toast.LENGTH_SHORT).show();
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
Toast.makeText(BluetoothActivity.this, "result batch", Toast.LENGTH_SHORT).show();
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
Toast.makeText(BluetoothActivity.this, "ERRORRR scan!!!" , Toast.LENGTH_SHORT).show();
}
};
ScanSettings scanSettings = new ScanSettings.Builder().
setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).
setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
//.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.setReportDelay(0)
.build();
/*final BluetoothAdapter.LeScanCallback mscanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
Toast.makeText(BluetoothActivity.this, device.getName()+ " "+device.getAddress() , Toast.LENGTH_SHORT).show();
}
}; */
if(enable){
if (bleScanner != null) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
bleScanner.stopScan(scanCallback);
// BA.stopLeScan(mscanCallback);
}
},30000);
//BA.startLeScan(mscanCallback);
bleScanner.startScan(null, scanSettings, scanCallback);
//bleScanner.startScan(scanCallback);
Toast.makeText(BluetoothActivity.this, "Scan Started!", Toast.LENGTH_SHORT).show();
//lv.setAdapter(adapter);
} else {
Toast.makeText(BluetoothActivity.this, "Couldn't get Scanner object", Toast.LENGTH_SHORT).show();
}}
if(!enable) { try{
bleScanner.stopScan(scanCallback);
// BA.stopLeScan(mscanCallback);
Toast.makeText(BluetoothActivity.this, "scan stopped!", Toast.LENGTH_SHORT).show();}
catch (IllegalStateException e){
Toast.makeText(BluetoothActivity.this, "Illegal state exception "+e, Toast.LENGTH_SHORT).show();
}
}
}
Bluetooth devices send advertising packets (PDUs) to broadcast data,
and to allow other devices (scanners) to find and connect to them.
所以,如果您附近没有广告设备,您的扫描仪将找不到任何东西。
在这里您可以找到有关广告和扫描的详细信息:
https://dev.ti.com/tirex/explore/node?node=AD4sGbaamTCyn0DvZgBAsg__krol.2c__LATEST
谁能帮帮我?我想使用低功耗蓝牙扫描附近的设备,但是当我扫描它时,它给我随机地址,名称为 null 这是我的代码: 当我在两个 phone 上打开 BLE 广告时,我下载了一个名为 BLE 扫描仪的应用程序,之后我在我的应用程序上打开我的扫描,它给了我真实的地址,否则什么都没有发生,我的 phone 没有t 扫描任何 phone :(
public void scanBLEDevices(Boolean enable) {
final ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
Toast.makeText(BluetoothActivity.this, "result scan", Toast.LENGTH_SHORT).show();
BluetoothDevice device = result.getDevice();
String bluetoothAddressScanned = device.getAddress();
Toast.makeText(BluetoothActivity.this, bluetoothAddressScanned + " "+device.getName()+result.getRssi(), Toast.LENGTH_SHORT).show();
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
Toast.makeText(BluetoothActivity.this, "result batch", Toast.LENGTH_SHORT).show();
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
Toast.makeText(BluetoothActivity.this, "ERRORRR scan!!!" , Toast.LENGTH_SHORT).show();
}
};
ScanSettings scanSettings = new ScanSettings.Builder().
setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).
setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
//.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
.setReportDelay(0)
.build();
/*final BluetoothAdapter.LeScanCallback mscanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
Toast.makeText(BluetoothActivity.this, device.getName()+ " "+device.getAddress() , Toast.LENGTH_SHORT).show();
}
}; */
if(enable){
if (bleScanner != null) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
bleScanner.stopScan(scanCallback);
// BA.stopLeScan(mscanCallback);
}
},30000);
//BA.startLeScan(mscanCallback);
bleScanner.startScan(null, scanSettings, scanCallback);
//bleScanner.startScan(scanCallback);
Toast.makeText(BluetoothActivity.this, "Scan Started!", Toast.LENGTH_SHORT).show();
//lv.setAdapter(adapter);
} else {
Toast.makeText(BluetoothActivity.this, "Couldn't get Scanner object", Toast.LENGTH_SHORT).show();
}}
if(!enable) { try{
bleScanner.stopScan(scanCallback);
// BA.stopLeScan(mscanCallback);
Toast.makeText(BluetoothActivity.this, "scan stopped!", Toast.LENGTH_SHORT).show();}
catch (IllegalStateException e){
Toast.makeText(BluetoothActivity.this, "Illegal state exception "+e, Toast.LENGTH_SHORT).show();
}
}
}
Bluetooth devices send advertising packets (PDUs) to broadcast data, and to allow other devices (scanners) to find and connect to them.
所以,如果您附近没有广告设备,您的扫描仪将找不到任何东西。 在这里您可以找到有关广告和扫描的详细信息:
https://dev.ti.com/tirex/explore/node?node=AD4sGbaamTCyn0DvZgBAsg__krol.2c__LATEST