4

I would like input in deciding what API-accessible field in Android is the best equivalent to an iPhone's "device name" (it will be used as non-essential login data passed to a server). By device name, I do not mean "model", or any hardware- or software-related identifier, but more to do with the owner. See How do you get an iPhone's device name for exactly what I'm referencing.

As an additional example, when faced with the same problem in BlackBerry, it was decided that the owner name was the best equivalent. (See answer in Get Blackberry Owner details (eg name/number) through API )

So far, it looks to me like the best android-equivalent is using an AccountManager to return someone's google account email; see How can you get an Android user's email address?. This seems to me like a pretty rough approximation, though; and would require adding another whole permission to the app just for some non-essential login data. Does anyone know of a better equivalent, and how to grab it?

Many thanks!

Community
  • 1
  • 1
Cephron
  • 1,577
  • 1
  • 19
  • 26

2 Answers2

3

If you look in Settings -> Wireless & Network Setting -> Bluetooth Settings There is an option to set the device name. If the device name has not been set then I think it uses the persons account. You can access it through the BluetoothDevice.getName() method. Not sure if that helps.

DRiFTy
  • 11,269
  • 11
  • 61
  • 77
  • Looks like a potential candidate - I have two questions about it: 1. BluetoothDevice.getName() is not a static method, and in the api it seems to be for getting the name of remote devices - how would one obtain a BluetoothDevice object representing one's own device? 2. What "account" does it reference, if the device name has not been set? – Cephron Mar 17 '11 at 16:10
  • 1
    Yea since its not a static method you will need to set that equal to a service. I dont have any of my code available to me right now but i think i actually used the BluetoothAdapter class and that will allow you get a handle on the local bluetooth adapter. Try this... BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); String name = bt.getName(); – DRiFTy Mar 17 '11 at 16:22
  • Oh, got it for #1: use BluetoothAdapter.getDefaultAdapter.getName(); But it's returning null - I suppose that means I don't have the kind of account it uses. Anyway, I also like your answer because it seems that it could work for both phones and tablets. – Cephron Mar 17 '11 at 16:24
  • 1
    Be sure to include the permission to access the bluetooth device in the manifest... android.permission.BLUETOOTH – DRiFTy Mar 17 '11 at 16:28
0

BluetoothAdapter.getDefaultAdapter.getName() is also returning null if the user has switched off BT e.g. for saving battery or for security reasons. So it's not reliable, I'd say.

Jockel
  • 191
  • 2
  • 10