Closing Bluetooth connection. - Android Bluetooth

Android examples for Bluetooth:Turn off bluetooth

Description

Closing Bluetooth connection.

Demo Code


//package com.java2s;

import java.io.IOException;

import android.bluetooth.BluetoothSocket;

public class Main {

    private static BluetoothSocket mBluetoothSocket = null;

    private static boolean mConnected = false;

    /**/*from ww  w.j a v a  2s . co  m*/
     * Closing Bluetooth connection.
     */
    private static void disconnect() {
        if (mConnected) {
            try {
                if (mBluetoothSocket != null) {
                    mBluetoothSocket.close();
                    mBluetoothSocket = null;
                }
            } catch (IOException e) {
                mBluetoothSocket = null;
            }
        }
        mConnected = false;
    }
}

Related Tutorials