protected override void OnResume() { base.OnResume(); _bluetoothReceiver = new BluetoothReceiver(this); IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound); filter.AddAction(BluetoothAdapter.ActionDiscoveryFinished); filter.AddAction(BluetoothDevice.ActionPairingRequest); filter.AddAction(BluetoothDevice.ActionBondStateChanged); filter.AddAction(BluetoothAdapter.ActionDiscoveryStarted); filter.AddAction(BluetoothAdapter.ActionConnectionStateChanged); RegisterReceiver(_bluetoothReceiver, filter); }
//protected override Fragment CreateFragment() //{ // return null;//BluetoothFragment.NewInstance(this as MainActivity); //} protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.bluetooth_utils_fragment); Button search = FindViewById <Button>(Resource.Id.search_button); ListView listview = FindViewById <ListView>(Resource.Id.device_list); if (mBluetooth == null) { mBluetooth = new Bluetooth(); } mBluetoothAdapter = BluetoothAdapter.DefaultAdapter; mBluetoothReceiver = new BluetoothReceiver(this); IntentFilter filter = new IntentFilter(BluetoothDevice.ActionFound); filter.AddAction(BluetoothAdapter.ActionDiscoveryFinished); filter.AddAction(BluetoothDevice.ActionPairingRequest); filter.AddAction(BluetoothDevice.ActionBondStateChanged); filter.AddAction(BluetoothAdapter.ActionDiscoveryStarted); RegisterReceiver(mBluetoothReceiver, filter); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothDevice.ActionBondStateChanged)); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished)); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothAdapter.ActionDiscoveryStarted)); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothDevice.ActionFound)); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothDevice.ActionPairingRequest)); RegisterReceiver(mBluetoothReceiver, new IntentFilter(BluetoothAdapter.ActionRequestDiscoverable)); search.Click += delegate { mBluetoothAction = BluetoothAction.GetListOfAvailableDevices; mScanStarted = true; // cancel any requests which may be in progress mBluetoothAdapter.CancelDiscovery(); mBluetoothAdapter.StartDiscovery(); }; listview.ItemClick += delegate { }; }