Search in sources :

Example 51 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project Gadgetbridge by Freeyourgadget.

the class DeviceHelper method getAvailableDevices.

/**
     * Returns the list of all available devices that are supported by Gadgetbridge.
     * Note that no state is known about the returned devices. Even if one of those
     * devices is connected, it will report the default not-connected state.
     *
     * Clients interested in the "live" devices being managed should use the class
     * DeviceManager.
     * @param context
     * @return
     */
public Set<GBDevice> getAvailableDevices(Context context) {
    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    Set<GBDevice> availableDevices = new LinkedHashSet<GBDevice>();
    if (btAdapter == null) {
        GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
    } else if (!btAdapter.isEnabled()) {
        GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
    }
    List<GBDevice> dbDevices = getDatabaseDevices();
    // these come first, as they have the most information already
    availableDevices.addAll(dbDevices);
    if (btAdapter != null) {
        List<GBDevice> bondedDevices = getBondedDevices(btAdapter);
        availableDevices.addAll(bondedDevices);
    }
    Prefs prefs = GBApplication.getPrefs();
    String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
    if (miAddr.length() > 0) {
        GBDevice miDevice = new GBDevice(miAddr, "MI", DeviceType.MIBAND);
        availableDevices.add(miDevice);
    }
    String pebbleEmuAddr = prefs.getString("pebble_emu_addr", "");
    String pebbleEmuPort = prefs.getString("pebble_emu_port", "");
    if (pebbleEmuAddr.length() >= 7 && pebbleEmuPort.length() > 0) {
        GBDevice pebbleEmuDevice = new GBDevice(pebbleEmuAddr + ":" + pebbleEmuPort, "Pebble qemu", DeviceType.PEBBLE);
        availableDevices.add(pebbleEmuDevice);
    }
    return availableDevices;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BluetoothAdapter(android.bluetooth.BluetoothAdapter) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 52 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ParanoidAndroid.

the class QuickSettingsModel method addBluetoothTile.

// Bluetooth
void addBluetoothTile(QuickSettingsTileView view, RefreshCallback cb) {
    mBluetoothTile = view;
    mBluetoothCallback = cb;
    final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    mBluetoothState.enabled = adapter.isEnabled();
    mBluetoothState.connected = (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED);
    onBluetoothStateChange(mBluetoothState);
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 53 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ParanoidAndroid.

the class BluetoothController method updateBondedBluetoothDevices.

private void updateBondedBluetoothDevices() {
    mBondedDevices.clear();
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        Set<BluetoothDevice> devices = adapter.getBondedDevices();
        if (devices != null) {
            for (BluetoothDevice device : devices) {
                if (device.getBondState() != BluetoothDevice.BOND_NONE) {
                    mBondedDevices.add(device);
                }
            }
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 54 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ParanoidAndroid.

the class BatteryStatsService method noteBluetoothOn.

public void noteBluetoothOn() {
    enforceCallingPermission();
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }
    synchronized (mStats) {
        if (mBluetoothHeadset != null) {
            mStats.noteBluetoothOnLocked();
            mStats.setBtHeadset(mBluetoothHeadset);
        } else {
            mBluetoothPendingStats = true;
        }
    }
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 55 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by ParanoidAndroid.

the class ExternalSharedPermsTest method testRunLocationAndBluetooth.

/** The use of location manager and bluetooth below are simply to simulate an app that
     *  tries to use them, so we can verify whether permissions are granted and accessible.
     * */
public void testRunLocationAndBluetooth() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
        mBluetoothAdapter.getName();
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)87 Intent (android.content.Intent)15 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 LocationManager (android.location.LocationManager)12 Bundle (android.os.Bundle)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 IntentFilter (android.content.IntentFilter)7 Handler (android.os.Handler)6 TextToSpeech (android.speech.tts.TextToSpeech)6 ArrayAdapter (android.widget.ArrayAdapter)6 TextView (android.widget.TextView)6 BluetoothActivityEnergyInfo (android.bluetooth.BluetoothActivityEnergyInfo)5 BluetoothProfile (android.bluetooth.BluetoothProfile)5 ServiceListener (android.bluetooth.BluetoothProfile.ServiceListener)5 ScanFilter (android.bluetooth.le.ScanFilter)5 WifiActivityEnergyInfo (android.net.wifi.WifiActivityEnergyInfo)5 RemoteException (android.os.RemoteException)5 SynchronousResultReceiver (android.os.SynchronousResultReceiver)5 ModemActivityInfo (android.telephony.ModemActivityInfo)5