android - 是否可以过滤蓝牙扫描结果以显示具有特定名称的设备
解决方案
是的,你可以过滤掉它。
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String deviceName = device.getName();
//
// use try-catch to keep tying on the logic -- John Melody added
try {
if (deviceName.contains("somethingsomething")) {
System.out.println(String.format("Ok %s", deviceName));
}
} catch(Exception e) {
e.printStackTrace();
}
//
}
}
};
结帐[this][1] 链接
[1] : https://developer.android.com/guide/topics/connectivity/bluetooth#FindingDevices