Search in sources :

Example 61 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android by JetBrains.

the class UnitTest 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 62 with BluetoothAdapter

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

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 63 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method onHealthDevicePropertyChanged.

/*package*/
void onHealthDevicePropertyChanged(String devicePath, String channelPath) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    //TODO: Fix this in Bluez
    if (channelPath.equals("/")) {
        // This means that the main channel is being destroyed.
        return;
    }
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config = findHealthApplication(device, channelPath);
    if (config != null) {
        HealthChannel chan = findChannelByPath(device, channelPath);
        if (chan == null) {
            errorLog("Health Channel is not present:" + channelPath);
        } else {
            chan.mMainChannel = true;
        }
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 64 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project XobotOS by xamarin.

the class AudioService method getBluetoothHeadset.

private boolean getBluetoothHeadset() {
    boolean result = false;
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
        result = adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, BluetoothProfile.HEADSET);
    }
    // If we could not get a bluetooth headset proxy, send a failure message
    // without delay to reset the SCO audio state and clear SCO clients.
    // If we could get a proxy, send a delayed failure message that will reset our state
    // in case we don't receive onServiceConnected().
    sendMsg(mAudioHandler, MSG_BT_HEADSET_CNCT_FAILED, 0, SENDMSG_REPLACE, 0, 0, null, result ? BT_HEADSET_CNCT_TIMEOUT_MS : 0);
    return result;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 65 with BluetoothAdapter

use of android.bluetooth.BluetoothAdapter in project android-beacon-library by AltBeacon.

the class CycledLeScannerForLollipop method isBluetoothOn.

private boolean isBluetoothOn() {
    try {
        BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
        if (bluetoothAdapter != null) {
            return (bluetoothAdapter.getState() == BluetoothAdapter.STATE_ON);
        }
        LogManager.w(TAG, "Cannot get bluetooth adapter");
    } catch (SecurityException e) {
        LogManager.w(TAG, "SecurityException checking if bluetooth is on");
    }
    return false;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

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