Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothDevice"/> class from the Java BluetoothDevice.
        /// </summary>
        /// <param name="bluetoothDeviceJavaObject">
        /// The Java object that is an instance of android.bluetooth.BluetoothDevice.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="bluetoothDeviceJavaObject"/> is null.
        /// </exception>
        internal BluetoothDevice(AndroidJavaObject bluetoothDeviceJavaObject)
        {
            try {
                if (bluetoothDeviceJavaObject.IsNull())
                {
                    throw new ArgumentNullException("bluetoothDeviceJavaObject");
                }

                Name      = bluetoothDeviceJavaObject.Call <string>("getName").Trim();
                Address   = bluetoothDeviceJavaObject.Call <string>("getAddress");
                BondState = (DeviceBondState)bluetoothDeviceJavaObject.Call <int>("getBondState");

                AndroidJavaObject deviceClassJavaObject = bluetoothDeviceJavaObject.Call <AndroidJavaObject>("getBluetoothClass");
                int deviceClassFull = deviceClassJavaObject.Call <int>("getDeviceClass");
                DeviceClass      = (BluetoothDeviceClass.Class)deviceClassFull;
                DeviceMajorClass = DeviceClass.GetMajorClass();
                IsConnectable    = DeviceClass.IsProbablyHandheldDataCapableDevice();

                if (Name == string.Empty)
                {
                    Name = Address;
                }
            } catch {
                Debug.LogError("Exception while converting BluetoothDevice");
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BluetoothDevice"/> class.
        /// </summary>
        /// <param name="deviceString">
        /// The device string.
        /// </param>
        internal BluetoothDevice(string deviceString)
        {
            try {
                string[] tokens =
                    deviceString.Split(
                        new[] { AndroidBluetoothMultiplayer.kDataDelimiter },
                        StringSplitOptions.None
                        );

                Name      = tokens[0].Trim();
                Address   = tokens[1];
                BondState = (DeviceBondState)byte.Parse(tokens[2]);
                int deviceClassFull = int.Parse(tokens[3]);

                DeviceClass      = (BluetoothDeviceClass.Class)deviceClassFull;
                DeviceMajorClass = DeviceClass.GetMajorClass();
                IsConnectable    = DeviceClass.IsProbablyHandheldDataCapableDevice();

                if (Name == string.Empty)
                {
                    Name = Address;
                }
            } catch {
                Debug.LogError(string.Format("Exception while parsing BluetoothDevice, string was: {0}", deviceString));
                throw;
            }
        }