Search in sources :

Example 96 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class Status method setBtStatus.

private void setBtStatus() {
    BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
    Preference btAddressPref = findPreference(KEY_BT_ADDRESS);
    if (bluetooth == null) {
        // device not BT capable
        getPreferenceScreen().removePreference(btAddressPref);
    } else {
        String address = bluetooth.isEnabled() ? bluetooth.getAddress() : null;
        btAddressPref.setSummary(!TextUtils.isEmpty(address) ? address : getString(R.string.status_unavailable));
    }
}
Also used : Preference(android.preference.Preference) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 97 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class BluetoothNamePreference method persistString.

@Override
protected boolean persistString(String value) {
    BluetoothAdapter adapter = mLocalManager.getBluetoothAdapter();
    adapter.setName(value);
    return true;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 98 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_packages_apps_Settings by LineageOS.

the class CachedBluetoothDeviceManager method readPairedDevices.

private synchronized boolean readPairedDevices() {
    BluetoothAdapter adapter = mLocalManager.getBluetoothAdapter();
    Set<BluetoothDevice> bondedDevices = adapter.getBondedDevices();
    if (bondedDevices == null)
        return false;
    boolean deviceAdded = false;
    for (BluetoothDevice device : bondedDevices) {
        CachedBluetoothDevice cachedDevice = findDevice(device);
        if (cachedDevice == null) {
            cachedDevice = new CachedBluetoothDevice(mLocalManager.getContext(), device);
            mCachedDevices.add(cachedDevice);
            dispatchDeviceAdded(cachedDevice);
            deviceAdded = true;
        }
    }
    return deviceAdded;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 99 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project fdroidclient by f-droid.

the class BluetoothServer method run.

@Override
public void run() {
    final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    try {
        serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid());
    } catch (IOException e) {
        Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now", e);
        return;
    }
    while (true) {
        if (isInterrupted()) {
            Utils.debugLog(TAG, "Server stopped so will terminate loop looking for client connections.");
            break;
        }
        if (!adapter.isEnabled()) {
            Utils.debugLog(TAG, "User disabled Bluetooth from outside, stopping.");
            break;
        }
        try {
            BluetoothSocket clientSocket = serverSocket.accept();
            if (clientSocket != null) {
                if (isInterrupted()) {
                    Utils.debugLog(TAG, "Server stopped after socket accepted from client, but before initiating connection.");
                    break;
                }
                ClientConnection client = new ClientConnection(clientSocket, webRoot);
                client.start();
                clients.add(client);
            }
        } catch (IOException e) {
            Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients", e);
        }
    }
}
Also used : IOException(java.io.IOException) BluetoothSocket(android.bluetooth.BluetoothSocket) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 100 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project xDrip by NightscoutFoundation.

the class JoH method isBluetoothEnabled.

public static boolean isBluetoothEnabled(final Context context) {
    try {
        final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
        // local scope only
        final BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
        return mBluetoothAdapter.isEnabled();
    } catch (Exception e) {
        UserError.Log.d(TAG, "isBluetoothEnabled() exception: " + e);
    }
    return false;
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) BluetoothAdapter(android.bluetooth.BluetoothAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)207 Intent (android.content.Intent)32 BluetoothDevice (android.bluetooth.BluetoothDevice)25 BluetoothManager (android.bluetooth.BluetoothManager)20 IntentFilter (android.content.IntentFilter)16 LocationManager (android.location.LocationManager)15 BluetoothPan (android.bluetooth.BluetoothPan)14 BluetoothProfile (android.bluetooth.BluetoothProfile)13 Bundle (android.os.Bundle)13 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 TextView (android.widget.TextView)12 Method (java.lang.reflect.Method)10 Test (org.junit.Test)10 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)9 ScanSettings (android.bluetooth.le.ScanSettings)9 List (java.util.List)9 ScanCallback (android.bluetooth.le.ScanCallback)8 ScanResult (android.bluetooth.le.ScanResult)8 Handler (android.os.Handler)8