getDeviceName without bluetooth permission
See original GitHub issueFeature 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:
- Created 4 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just implemented this for v3
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