예제 #1
0
        protected void onDestroy()
        {
            base.OnDestroy();

            ActionFoundReceiver receiver = new ActionFoundReceiver(this);

            UnregisterReceiver(receiver);
            //blueToothTextView = FindViewById<TextView>(Resource.Id.BlueToothResults);
            //blueToothTextView.Text += btDeviceList;
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.BlueToothView);
            InitializeLocationManager();

            //blueToothTextView = FindViewById<TextView>(Resource.Id.BlueToothResults);
            blueToothListView = FindViewById <ListView>(Resource.Id.BlueToothResultsListView);

            //blueToothTextView.MovementMethod = new ScrollingMovementMethod();
            //Register the BroadcastReceiver
            receiver = new ActionFoundReceiver(this);
            IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound);

            filter.AddAction(BluetoothDevice.ActionUuid);
            filter.AddAction(BluetoothAdapter.ActionDiscoveryStarted);
            filter.AddAction(BluetoothAdapter.ActionDiscoveryFinished);

            RegisterReceiver(receiver, filter); // Don't forget to unregister during onDestroy

            // Getting the Bluetooth adapter
            btAdapter = BluetoothAdapter.DefaultAdapter;
            //blueToothTextView.Text += "\nAdapter: " + btAdapter;

            Button startButton = FindViewById <Button>(Resource.Id.startBlueToothButton);

            startButton.Click += (object sender, EventArgs e) =>
            {
                //blueToothTextView.SetHeight(1200);
                blueToothListView.SetMinimumHeight(0);
                CheckBTState();
                receiver.OutputBlueToothList(this);
                //btAdapter.StartDiscovery();
            };

            Button stopButton = FindViewById <Button>(Resource.Id.stopBlueToothButton);

            stopButton.Click += (object sender, EventArgs e) =>
            {
                btAdapter.StopLeScan(receiver);
                receiver.OutputBlueToothList(this);
            };
        }