Android - How to enable Bluetooth to be always on?

后端 未结 6 1134
太阳男子
太阳男子 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

提交回复
热议问题