Handles closing the Bluetooth socket and flushes/closes output stream if there is any data left in the buffer. - Android Bluetooth

Android examples for Bluetooth:Bluetooth Data Transfer

Description

Handles closing the Bluetooth socket and flushes/closes output stream if there is any data left in the buffer.

Demo Code


//package com.java2s;
import java.io.IOException;
import java.io.OutputStream;

import android.bluetooth.BluetoothSocket;

public class Main {
    public static BluetoothSocket mBluetoothSocket = null;
    public static OutputStream mOutputStream = null;

    /**/* w  w w.  j  av  a  2s.c om*/
     * Handles closing the socket and flushes/closes output stream if
     * there is any data left in the buffer.
     */
    public static void teardown() {
        try {
            if (mBluetoothSocket != null) {
                mBluetoothSocket.close();
            }
            if (mOutputStream != null) {
                mOutputStream.flush();
                mOutputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials