0

In Android you can set a username for the device. I've set up a few devices where it asked me for my first name and last name. I was wondering how to retrieve this. In iOS you can get a name like "Kate's iPhone" for the device name which is what I want to do on Android. Additionally in a game I'd like to fill in the Characters name with the persons name. So I could essentially say String.format("Hello, %s", getUsername); Is this possible in Android down to API 10? The only thing I've found is UserManager with a getUserName() method, but it is only available at API level 17 which I think lines up with when Android allowed tablets to have multi user support... so I'm not sure it will actually give a valid response on a phone. Does anyone have any ideas?

I am not looking for device name (e.g. Nexus 7, Nexus 4, Samsung Galaxy S5).

  • Have you checked [this](http://stackoverflow.com/questions/16704597/how-do-you-get-the-user-defined-device-name-in-android)? Didn't work for me (using an emulator), I'm not sure if this works on a real phone. – jmm Dec 17 '14 at 17:26
  • How the hell did I get downvoted. Totally legitimate question. –  Dec 17 '14 at 17:38

1 Answers1

0

This works on a real phone, in an Emulator you will get an empty String.

BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
String deviceName = myDevice.getName();
Toast.makeText(this, "Phone "+deviceName, Toast.LENGTH_LONG).show();

Remember to add the permission to the Manifest:

<uses-permission android:name="android.permission.BLUETOOTH"/>
jmm
  • 1,044
  • 2
  • 12
  • 38
  • Hm... Adding a bluetooth permission is probably not what I want to do. Appreciate the answer though. I'll stay open to more. –  Dec 17 '14 at 18:01