private void TriggerPicked(string m) { if (OnDevicePicked != null) { string[] split = m.Split(new string[] { "#$" }, StringSplitOptions.None); if (split.Length < 2) { return; } string name; if (split.Length > 2) //As the Name migh contain '#$' so we need to take the last three { name = split [0]; //i=split.Length -1 is the last split for name for (int i = 1; i < split.Length - 1; i++) { name += "#$" + split [i]; } } else { name = split [0]; } string macAddress = split [split.Length - 1]; BluetoothDevice tmp = new BluetoothDevice(true); tmp.initDeviceAsStruct_withNoJava(macAddress, name); OnDevicePicked(tmp); } }
/*Old method * public static BluetoothDevice[] getBondedDevices () * { * AndroidJavaObject[] paired = BtBridge.Instance.getPairedDevices (); * if (paired == null || paired.Length == 0) * return null; * * BluetoothDevice[] devices = new BluetoothDevice[paired.Length]; * for (int i=0; i<paired.Length; i++) { * devices [i] = new BluetoothDevice (paired [i]); * } * return devices; * } */ /// <summary> /// Returns array of paired/bonded devices. /// </summary> /// <returns><c>BluetoothDevice</c> array of the paired devices on your Android.</returns> public static BluetoothDevice[] getPairedDevices() { String[] bonded = BtBridge.Instance.getBondedDevices(); if (bonded == null || bonded.Length == 0) { return(null); } BluetoothDevice[] devices = new BluetoothDevice[bonded.Length / 2]; for (int i = 0; i < bonded.Length; i += 2) { BluetoothDevice tmp = new BluetoothDevice(true); tmp.initDeviceAsStruct_withNoJava(bonded [i + 1], bonded [i]); //Connection will change to by Name devices [i / 2] = tmp; } return(devices); }
private void TrDiscoveredDevice(string m) { if (OnDeviceDiscovered != null) { string[] split = m.Split(new string[] { "#$" }, StringSplitOptions.None); if (split.Length < 3) { return; } string name; if (split.Length > 3) //As the Name migh contain '#$' so we need to take the last three { name = split [0]; //i=split.Length -3 is the last split for name for (int i = 1; i < split.Length - 2; i++) { name += "#$" + split [i]; } } else { name = split [0]; } string macAddress = split [split.Length - 2]; short rssi; if (!short.TryParse(split [split.Length - 1], out rssi)) //The last element is RSSI { rssi = 0; } BluetoothDevice device = new BluetoothDevice(); device.initDeviceAsStruct_withNoJava(macAddress, name); //Connection will change to by Name OnDeviceDiscovered(device, rssi); } }