Android - How to enable Bluetooth to be always on?

后端 未结 6 2187
长情又很酷
长情又很酷 2021-02-07 15:58

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:24

     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

提交回复
热议问题