Search in sources :

Example 46 with BluetoothAdapter

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);
}
Also used : ServiceListener(android.bluetooth.BluetoothProfile.ServiceListener) BluetoothProfile(android.bluetooth.BluetoothProfile) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 47 with BluetoothAdapter

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);
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter) Test(org.junit.Test)

Example 48 with BluetoothAdapter

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);
    }
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter) SimpleHogBug(edu.berkeley.cs.amplab.carat.android.storage.SimpleHogBug)

Example 49 with BluetoothAdapter

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;
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) Intent(android.content.Intent) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 50 with BluetoothAdapter

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;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) GBException(nodomain.freeyourgadget.gadgetbridge.GBException) Method(java.lang.reflect.Method) BluetoothAdapter(android.bluetooth.BluetoothAdapter) GBException(nodomain.freeyourgadget.gadgetbridge.GBException)

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