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;
}
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);
}
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);
}
}
}
}
}
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;
}
}
}
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();
}
}
Aggregations