Currently i am programming USB Bluetooth Dongle in C# 2010. I want to program in such a way that it automatically pairs with the Bluetooth device found. I don't want the user to manually accept the pairing request in both Mobile phone as well as in Windows 7. I am using my phone (X Peria S) to test this. Is this method of programming possible? I tried to code this using 32feet.net library for the Bluetooth, here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Guid service = BluetoothService.BluetoothBase;
private BluetoothClient bluetoothClient;
public Form1()
{
InitializeComponent();
}
private void Search_Bluetooth(object sender, EventArgs e)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo [] bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
}
private void Pair(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
MessageBox.Show("Connected");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
When i run this project i see the list of Bluetooth device in the surrounding but when ever i want to pair with it gives me an error saying "A connection attempt failed because the connected party did not properly respond a period of time"
I think the problem is private Guid service = BluetoothService.BluetoothBase but i am not sure, am i using the right service .BluetoothBase to pair with my phone?
Is there any existing solution for this? Any help and suggestion is highly appreciated.
Thanks.