question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getDeviceName without bluetooth permission

See original GitHub issue

Feature Request

getDeviceName should be updated to use an api that doesn’t require permissions. There is a newer API that allows this. There is also an undocumented way of getting it without the permission.

Why it is needed

Adding the Bluetooth permission just to get the device name is unnecessary and confusing to users.

Possible implementation

if (Build.VERSION.SDK_INT >= 25) {
    return Settings.Global.getString(getContentResolver(), Settings.Global.DEVICE_NAME);
} else {
    return Settings.Secure.getString(getContentResolver(), "bluetooth_name");
}

Code sample

Same as existing but without the Bluetooth permission

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mikehardycommented, Aug 29, 2019

I just implemented this for v3

0reactions
mikehardycommented, Sep 1, 2019

I went a slightly different way with this one after testing.

Previously we were relying entirely on bluetooth name but with permission.

This proposed implementation worked but gave a different result, and in the end did not give my phone’s actual system name despite it being set (!)

So rather than check for API25 and give priority to a new piece of information (“device_name”) which apparently does not give great results, I just went with the no-permission-required “bluetooth_name” by itself.

Seems to work for me now on emulator and real device, we’ll see how the implementation fairs in the wild

Read more comments on GitHub >

github_iconTop Results From Across the Web

getDeviceName without bluetooth permission #735 - GitHub
Adding the Bluetooth permission just to get the device name is unnecessary and confusing to users. Possible implementation. if (Build.VERSION.
Read more >
getDeviceName does not return device name on android
You need to add bluetooth permission in AndroidManifest.xml <uses-permission android:name="android.permission.BLUETOOTH"/>.
Read more >
How to get an Android Device Nickname | Capital One Tech
Note: #3 requires Bluetooth permission. Sources: Stack Overflow — How do you get the user defined “Device Name” in android?
Read more >
react-native-device-info - npm
Returns an object of platform-specfic location providers/servcies, with boolean value whether or not they are currently available. NOTE: This ...
Read more >
Bluetooth.requestDevice() - Web APIs | MDN
The Bluetooth.requestDevice() method of the Bluetooth interface returns a Promise to a BluetoothDevice object with the specified options.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found