Android - How to enable Bluetooth to be always on?

后端 未结 6 1141
太阳男子
太阳男子 2021-02-07 15:40

Two question on Bluetooth development on Android:

  1. Is there a way to enable Bluetooth to be always on (I might have a long device discovery phase in my applicati

相关标签:
6条回答
  • 2021-02-07 16:13
     private void ensureDiscoverable() {
        if(D) Log.d(TAG, "ensure discoverable");
        if (mBluetoothAdapter.getScanMode() !=
            BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
            Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
            startActivity(discoverableIntent);
        }
    

    http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_REQUEST_DISCOVERABLE

    0 讨论(0)
  • 2021-02-07 16:18

    BlueCove is an open-source bluetooth implementation for Java.

    It works on a lot of different machines and if correct there is a Android compatible version lurking around somewhere.

    0 讨论(0)
  • 2021-02-07 16:22

    The Bluez stack on Linux is an open source implementation. It's also available on Windows but the API is much more complete on Linux.

    When you say, 'enable Bluetooth to always be on' do you mean, always trying to discover other devices?

    Most bluetooth chips have a deep sleep mode, where the chip is mostly down and just comes up a to check for activity on any established links. It will only wake up to full power when you want it to do something (discovery, make a connection) or there is activity on an existing link.

    Yeah, it uses more battery power than if the Bluetooth were totally off but it's not a total vampire.

    0 讨论(0)
  • 2021-02-07 16:25

    Bluetooth implementation is now available in the Android 2.0 API. See this and this.

    0 讨论(0)
  • 2021-02-07 16:33

    Enabling Bluetooth to be always on, may not be a good decision, if your only concern is long discovery delay ("battery life"-wise).

    As for third-party Bluetooth APIs, the only thing that I've heard of is iAnywhere Blue SDK (from Sybase, not free, only evaluation version available), which covers some of the features, that will be supported in the future from the system/bluetooth and bluez packages.

    According to the Android's Bluetooth roadmap, most of the long waited things like Java API, Bluetooth 2.1 + EDR will be implemented, at one point in the future.

    Good luck with your project.

    0 讨论(0)
  • 2021-02-07 16:33

    On 2.3.6 I can keep the device always visible by putting the delay 0:

    Intent di = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    di.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
    
    0 讨论(0)
提交回复
热议问题