Paler
Paler

Reputation: 349

How to change the Android Bluetooth name in code?

Now I am using BluetoothAdapter.setName("newName"). However it seems not work... I use another Android Device to scanning the bluetooth that is renamed in code, but it is not changed...

How can I change the bluetooth device name and other device can see such change?

Upvotes: 0

Views: 3500

Answers (1)

maveroid
maveroid

Reputation: 1890

You need to make sure that bluetooth state is ON before changing the name. Are you doing that?

Here is the documentation for setName in android developer docs.

Set the friendly Bluetooth name of the local Bluetooth adapter.

This name is visible to remote Bluetooth devices.

Valid Bluetooth names are a maximum of 248 bytes using UTF-8 encoding, although many remote devices can only display the first 40 characters, and some may be limited to just 20.

If Bluetooth state is not STATE_ON, this API will return false. After turning on Bluetooth, wait for ACTION_STATE_CHANGED with STATE_ON to get the updated value.

Requires BLUETOOTH_ADMIN

Parameters name a valid Bluetooth name Returns true if the name was set, false otherwise

Upvotes: 1

Related Questions