Android Open Source - UltimateCom Bluetooth Transmission Activity






From Project

Back to project page UltimateCom.

License

The source code is released under:

GNU General Public License

If you think the Android project UltimateCom listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.ultimatecom;
// ww w.  j  a  va 2 s .c om
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;

public class BluetoothTransmissionActivity extends StreamTransmissionActivity {

    public static final String PARAM_BT_ADDRESS_KEY = "PARAM_BT_ADDRESS_KEY";

    private static final class BluetoothStreamTransmissionDevice implements IStreamTransmissionDevice {
        private final BluetoothSocket btSocket;
        private final InputStream inputStream;
        private final OutputStream outputStream;
        
        public BluetoothStreamTransmissionDevice(BluetoothSocket btSocket) throws IOException {
            this.btSocket = btSocket;
            inputStream = btSocket.getInputStream();
            outputStream = btSocket.getOutputStream();
        }
        
        @Override
        public InputStream getInputStream() {
            return inputStream;
        }

        @Override
        public OutputStream getOutputStream() {
            return outputStream;
        }

        @Override
        public void close() throws IOException {
            btSocket.close();
        }
    }

    @Override
    protected IStreamTransmissionDevice openDevice() throws IOException {
        final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice btDevice = btAdapter.getRemoteDevice(getIntent().getStringExtra(PARAM_BT_ADDRESS_KEY));
        
        BluetoothSocket btSocket = btDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
        btSocket.connect();
        
        String deviceName = btDevice.getName();
        if ((deviceName == null) || (deviceName.length() == 0)) {
            deviceName = btDevice.getAddress();
        }
        this.setTitle("BT Device: " + deviceName);
        
        return new BluetoothStreamTransmissionDevice(btSocket);
    }

}




Java Source Code List

org.ultimatecom.BluetoothConfigFragment.java
org.ultimatecom.BluetoothTransmissionActivity.java
org.ultimatecom.ConnectionConfigActivity.java
org.ultimatecom.IoioConfigFragment.java
org.ultimatecom.RingBufferCharSequence.java
org.ultimatecom.StreamTransmissionActivity.java
org.ultimatecom.TcpConfigFragment.java
org.ultimatecom.TransmissionActivity.java
org.ultimatecom.TtyConfigFragment.java
org.ultimatecom.TtyTransmissionActivity.java
org.ultimatecom.UsbSerialConfigFragment.java