using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
+using System.Reflection;
+using System.ComponentModel;
namespace Tizen.Network.Bluetooth
{
private Interop.Bluetooth.AuthorizationChangedCallback _authorizationChangedCallback;
private Interop.Bluetooth.ServiceSearchedCallback _serviceSearchedCallback;
private Interop.Bluetooth.DeviceConnectionStateChangedCallback _connectionChangedCallback;
+ private Interop.Bluetooth.ConnectedProfileCallback _connectedProfileCallback;
internal string RemoteDeviceAddress;
internal string RemoteDeviceName;
}
/// <summary>
+ /// The constructor
+ /// </summary>
+ /// <since_tizen> 9 </since_tizen>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public BluetoothDevice(BluetoothLeDevice leDevice)
+ {
+ RemoteDeviceAddress = leDevice?.RemoteAddress;
+ }
+
+ /// <summary>
/// The address of the device.
/// </summary>
/// <since_tizen> 3 </since_tizen>
if (BluetoothAdapter.IsBluetoothEnabled)
{
List<BluetoothProfileType> profileList = new List<BluetoothProfileType>();
- Interop.Bluetooth.ConnectedProfileCallback callback = (int profile, IntPtr userData) =>
+ _connectedProfileCallback = (int profile, IntPtr userData) =>
{
if (!profile.Equals(null))
{
}
return true;
};
- int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, callback, IntPtr.Zero);
+ int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, _connectedProfileCallback, IntPtr.Zero);
if (ret != (int)BluetoothError.None)
{
Log.Error(Globals.LogTag, "Failed to get connected profiles, Error - " + (BluetoothError)ret);
/// <remarks>
/// The Bluetooth must be enabled.
/// </remarks>
+ /// <returns>The profile instance.</returns>
/// <since_tizen> 3 </since_tizen>
public T GetProfile<T>() where T : BluetoothProfile
{
- // TODO : Need to check capability of supporting profiles
- var profile = Activator.CreateInstance<T>();
- profile.RemoteAddress = RemoteDeviceAddress;
- return profile;
+ try
+ {
+ // TODO : Need to check capability of supporting profiles
+ var profile = (T)Activator.CreateInstance(typeof(T), true);
+ profile.RemoteAddress = RemoteDeviceAddress;
+ return profile;
+ }
+ catch (TargetInvocationException err)
+ {
+ throw err.InnerException;
+ }
}
/// <summary>