Forum Xamarin.Android

Get device hostname (NetworkName)

Hello everyone,

I am trying to create an application in Xamarin.Android that detects device_hostname, device network name, but I really have not succeeded.
I tried to properties in Android.OS.BUILD, but none does not correspond with actuall device_hostname.
So I was wondering if there is any possibility of obtaining property system "net.hostname" in code.

Thank you for the advice.

Tagged:

Answers

  • AgenduumAgenduum USMember ✭✭

    Has anybody been able to do this?

  • Java.Lang.Class buildClass = Java.Lang.Class.ForName("android.os.Build");
    Java.Lang.Reflect.Method getString = buildClass.GetDeclaredMethod("getString", Java.Lang.Class.FromType(typeof(Java.Lang.String)));
    getString.Accessible = true;
    string hostname= getString.Invoke(null, "net.hostname").ToString();
    
Sign In or Register to comment.