Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.listBlueTooth);

            conn = new BluetoothConnection();
            conn.getAdapter();
            conn.thisAdapter.StartDiscovery();
            var Listview11 = FindViewById <ListView>(Resource.Id.listView1);

            Listview11.Adapter           = new HomeScreenAdapter(this, conn.GetBlueToothDevices());
            Listview11.FastScrollEnabled = true;
            Listview11.ItemClick        += Listview11_ItemClick;
            // Create your application here
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);


            latitude  = FindViewById <TextView>(Resource.Id.latitude);
            longitude = FindViewById <TextView>(Resource.Id.longitude);

            string          name    = Intent.GetStringExtra("adapter");
            BluetoothSocket _socket = null;

            try
            {
                //listenThread.Start();

                myConnection = new BluetoothConnection();
                myConnection.getAdapter();
                myConnection.thisAdapter.StartDiscovery();
                myConnection.getDevice(name);
                myConnection.thisDevice.SetPairingConfirmation(false);
                myConnection.thisDevice.SetPairingConfirmation(true);
                myConnection.thisDevice.CreateBond();
            }
            catch (Exception)
            {
            }


            myConnection.thisAdapter.CancelDiscovery();
            _socket = myConnection.thisDevice.CreateRfcommSocketToServiceRecord(Java.Util.UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
            myConnection.thisSocket = _socket;


            try
            {
                myConnection.thisSocket.Connect();


                beginListenForData();
                Toast.MakeText(this, "Successfully Connected with" + name, ToastLength.Long).Show();
            }
            catch (Exception)
            {
            }
        }