Ejemplo n.º 1
0
		/// <summary>
		/// Raises the activity result event.
		/// Connects to a new device from deviceListActivity
		/// </summary>
		/// <param name="requestCode">Request code.</param>
		/// <param name="resultCode">Result code.</param>
		/// <param name="data">Data.</param>
		protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
		{

			switch (requestCode) {
			case REQUEST_CONNECT_DEVICE:
				// When DeviceListActivity returns with a device to connect
				if (resultCode == Result.Ok) {
					// Get the device MAC address
					var address = data.Extras.GetString (DeviceListActivity.EXTRA_DEVICE_ADDRESS);
					// Get the BLuetoothDevice object
					BluetoothDevice device = bluetoothAdapter.GetRemoteDevice (address);
					// Attempt to connect to the device
					service.Connect (device);
				}
				break;
			case REQUEST_ENABLE_BT:
				// When the request to enable Bluetooth returns
				if (resultCode == Result.Ok) {
					// Bluetooth is now enabled, so set up service
					service = new BluetoothChatService (this, handle);
				} else {
				
					// User did not enable Bluetooth or an error occured
					Toast.MakeText (this, Resource.String.bt_not_enabled_leaving, ToastLength.Short).Show ();
					Finish ();
				}
				break;
			}

			dialogSpin = new ProgressDialog (this, 5);
			dialogSpin.SetProgressStyle(ProgressDialogStyle.Spinner);
			dialogSpin.SetMessage("Waiting for Other Devices");
			dialogSpin.Indeterminate = true;

			SetContentView (Resource.Layout.WaitView);

			dialogSpin.Show ();
		}
Ejemplo n.º 2
0
		protected override void OnStart ()
		{
			base.OnStart ();

			// If BT is not on, request that it be enabled.
			// will then be called during onActivityResult
			// TODO maybe put in onCreate()
			if (!bluetoothAdapter.IsEnabled) {
				Intent enableIntent = new Intent (BluetoothAdapter.ActionRequestEnable);
				StartActivityForResult (enableIntent, REQUEST_ENABLE_BT);

				// Otherwise, setup the chat session
			} else 
				if (service == null){
					// Initialize the BluetoothChatService to perform bluetooth connections
					service = new BluetoothChatService (this, handle);
					//TODO MAYBE?
					for(int index = 0; index < BluetoothChatService.SIZE; index++){
						if (service.GetState (index) == BluetoothChatService.STATE_NONE) {
							// Start the Bluetooth chat services
							service.Start (index);
						}
					}
			}
		}
Ejemplo n.º 3
0
			public ConnectThread (BluetoothDevice device, BluetoothChatService service, int index)
			{
				mmDevice = device;
				_service = service;
				BluetoothSocket tmp = null;
				mmIndex = index;
				
				// Get a BluetoothSocket for a connection with the
				// given BluetoothDevice
				try {
					tmp = device.CreateRfcommSocketToServiceRecord (MY_UUID);
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "create() failed", e);
				}
				mmSocket = tmp;
			}
Ejemplo n.º 4
0
			public ConnectedThread (BluetoothSocket socket, BluetoothChatService service, int index)
			{
				Log.Debug (TAG, "create ConnectedThread: ");
				mmSocket = socket;
				_service = service;
				mmIndex = index;
				Stream tmpIn = null;
				Stream tmpOut = null;
	
				// Get the BluetoothSocket input and output streams
				try {
					tmpIn = socket.InputStream;
					tmpOut = socket.OutputStream;
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "temp sockets not created", e);
				}
	
				mmInStream = tmpIn;
				mmOutStream = tmpOut;
			}
Ejemplo n.º 5
0
			public AcceptThread (BluetoothChatService service, int index)
			{
				_service = service;
				BluetoothServerSocket tmp = null;
				mmIndex = index;
	
				// Create a new listening server socket TODO potential problem with names?
				try {
					tmp = _service._adapter.ListenUsingRfcommWithServiceRecord (NAME, MY_UUID);
	
				} catch (Java.IO.IOException e) {
					Log.Error (TAG, "listen() failed", e);
				}
				mmServerSocket = tmp;
			}