use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by crdroidandroid.
the class Tethering method setBluetoothTethering.
private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null || !adapter.isEnabled()) {
Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " + (adapter == null));
sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
return;
}
adapter.getProfileProxy(mContext, new ServiceListener() {
@Override
public void onServiceDisconnected(int profile) {
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
((BluetoothPan) proxy).setBluetoothTethering(enable);
// TODO: Enabling bluetooth tethering can fail asynchronously here.
// We should figure out a way to bubble up that failure instead of sending success.
int result = ((BluetoothPan) proxy).isTetheringOn() == enable ? ConnectivityManager.TETHER_ERROR_NO_ERROR : ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
sendTetherResult(receiver, result);
if (enable && isTetherProvisioningRequired()) {
scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
}
adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
}
}, BluetoothProfile.PAN);
}
use of android.bluetooth.BluetoothAdapter in project android-testing-templates by googlesamples.
the class LocalUnitTest method mockFinalClass.
@Test
public void mockFinalClass() {
BluetoothAdapter adapter = mock(BluetoothAdapter.class);
when(adapter.isEnabled()).thenReturn(true);
assertTrue(adapter.isEnabled());
verify(adapter).isEnabled();
verifyNoMoreInteractions(adapter);
}
use of android.bluetooth.BluetoothAdapter in project carat by amplab.
the class SettingsSuggestionAdapter method acceptDisableBluetooth.
private void acceptDisableBluetooth(ArrayList<SimpleHogBug> result) {
BluetoothAdapter myBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (myBluetoothAdapter.isEnabled() == true) {
SimpleHogBug item = new SimpleHogBug(a.getString(R.string.disablebluetooth), Constants.Type.OS);
result.add(item);
}
}
use of android.bluetooth.BluetoothAdapter in project Gadgetbridge by Freeyourgadget.
the class DiscoveryActivity method checkBluetoothAvailable.
private boolean checkBluetoothAvailable() {
BluetoothManager bluetoothService = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
if (bluetoothService == null) {
LOG.warn("No bluetooth available");
this.adapter = null;
return false;
}
BluetoothAdapter adapter = bluetoothService.getAdapter();
if (adapter == null) {
LOG.warn("No bluetooth available");
this.adapter = null;
return false;
}
if (!adapter.isEnabled()) {
LOG.warn("Bluetooth not enabled");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBtIntent);
this.adapter = null;
return false;
}
this.adapter = adapter;
return true;
}
use of android.bluetooth.BluetoothAdapter in project Gadgetbridge by Freeyourgadget.
the class DeviceHelper method removeBond.
/**
* Attempts to removing the bonding with the given device. Returns true
* if bonding was supposedly successful and false if anything went wrong
* @param device
* @return
*/
public boolean removeBond(GBDevice device) throws GBException {
BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
if (defaultAdapter != null) {
BluetoothDevice remoteDevice = defaultAdapter.getRemoteDevice(device.getAddress());
if (remoteDevice != null) {
try {
Method method = BluetoothDevice.class.getMethod("removeBond", (Class[]) null);
Object result = method.invoke(remoteDevice, (Object[]) null);
return Boolean.TRUE.equals(result);
} catch (Exception e) {
throw new GBException("Error removing bond to device: " + device, e);
}
}
}
return false;
}
Aggregations