3

I know this question is something that is often asked but no matter what I tried I couldn't find the answer.

I use an AVD android TV (API 24) and want to access this :

enter image description here

How can I access this name in my app ? Even with adb I never found it...

Kolopox
  • 276
  • 1
  • 4
  • 17
  • is that a name of your AVD? – Vladyslav Matviienko Jun 09 '17 at 08:31
  • @VladMatvienko Yes it's a name I defined myself in settings-->about-->device name – Kolopox Jun 09 '17 at 08:35
  • https://stackoverflow.com/a/33566247/940834 Try using the bluetooth provider. Use try, catch or check for nulls though, incase its not suported – IAmGroot Jun 09 '17 at 08:40
  • @Doomsknight I already tried but it return null. My adb doesn't seems to have bluetooth. But I can set the "device name", so I should be able to access it – Kolopox Jun 09 '17 at 08:43
  • You can probably access it on a real device, that has bluetooth, using that method. I suggest testing on a real device. Where as an AVD you will have issues. – IAmGroot Jun 09 '17 at 09:21
  • @Doomsknight I didn't test it, I will be able to in 1 or 2 hour, but I know that the android TV I'm testing with doesn't have bluetooth :/ is there a better solution ? – Kolopox Jun 09 '17 at 09:39
  • There are various suggestions on stackoverflow, but none that seem 100% reliable. – IAmGroot Jun 09 '17 at 10:03
  • @Doomsknight Can propose me some ? I already searched (if not I wouldn't have asked my queston) but I found nothing that worked. Even the guys that proposed ADB were wrong (in android TV at least) – Kolopox Jun 09 '17 at 10:10
  • Search for getting android device name, rather than specifically TV. As it should be the same solution. [example 1](https://stackoverflow.com/questions/7071281/get-android-device-name) [example 2](https://stackoverflow.com/questions/16704597/how-do-you-get-the-user-defined-device-name-in-android) – IAmGroot Jun 09 '17 at 10:18
  • @Doomsknight I already tried all oh them, to me they all return null expet for Build.Manufacturer + " " + Build.MODEL that is no really a name :/ To tell you I even tried a Linux command to search "MyAwesomeCustomeName" in adb but couldn't find it > – Kolopox Jun 09 '17 at 10:27
  • Bluetooth name is not the same as Device Name (at least not on some devices). The Pixel on Android P allows 2 different names for those 2 fields. – Richard Le Mesurier Feb 05 '19 at 13:19

1 Answers1

6

this is worked for my AVD (API level 24).

String deviceName = Settings.Global.getString(getContentResolver(), "device_name");

Instead of the string "device_name", you can also use the constant Settings.Global.DEVICE_NAME.


This property was moved into Settings.Global in API 17.

Before API 17, the following code should work:

String deviceName = Settings.System.getString(getContentResolver(), "device_name");
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
alian
  • 204
  • 1
  • 12
  • YOU ARE MY GOD !!!!!!!!!!! It worked just fine on AVD for me too ! I can't test on a real TV till monday but you can be sure I will post if it works or not ! Thanks man, really thank you ! – Kolopox Jun 09 '17 at 14:42