Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDeviceName without bluetooth permission #735

Closed
chris-feist opened this issue Jul 24, 2019 · 5 comments
Closed

getDeviceName without bluetooth permission #735

chris-feist opened this issue Jul 24, 2019 · 5 comments
Projects

Comments

@chris-feist
Copy link

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

@mikehardy
Copy link
Collaborator

I like the idea - happy to take a PR so long as it is backwards-compatible + documents that you can use the 'maxSdkVersion' attribute in the manifest when declaring the permission so that doesn't show up for folks that have access to the new API https://developer.android.com/training/permissions/requesting#declare-by-api-level

@mikehardy
Copy link
Collaborator

I just implemented this for v3

@chris-feist
Copy link
Author

Thank you! Sorry I don't have many devices to test with, so didn't implement it myself.

@mikehardy
Copy link
Collaborator

no problem. works so far on the emulator :-), and the implementation seems sane - I'm an android dev + react-native so I'm comfortable giving it a shot (obviously). Hoping to release an rc1 of v3 in the next day or so and we can all see.

@mikehardy mikehardy added this to Done in v3 Sep 1, 2019
@mikehardy
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v3
  
Done
Development

No branches or pull requests

2 participants