Does anyone know, how to get the username in Android using C# Xamarin?
I mean, when you in Android open:
Settings > System > About phone > [Name at the top] ?
Or:
Settings > System > About phone > Multiple users > You (the name) ?
I'm only interested in the user (display) name and not the e-mail nor the device name (which is not the same as the username).
I've tried with await Contacts.GetAllAsync()
using the required permissions, but the result was always empty.
Then I've tried with Environment.UserName
, but this returned "somebody"...
I did also found this post , but my code not find either the User
class or the CrossCurrentActivity
class that is mentioned in the code in the post...
Also the post describes installing a CurrentActivity plugin, but the page doesn't exist anymore...
I'm using Xamarin Forms with Shell (latest version) and Visual Studio 2019 Enterprise.
My Android version is 9.0.
Thank you.
UPDATE:
See this picture from the settings of my Android emulated device for explanation of, what I mean:
2条答案
按热度按时间tzdcorbm1#
根据您的需要,Xamarin.Essentials提供了一种特殊的方法来获取您的设备信息。
1.下载Xamarin。Nuget中的必备软件。
1.使用
var deviceName = DeviceInfo.Name;
来取得。有关详细信息,请参阅https://learn.microsoft.com/en-us/xamarin/essentials/device-information?tabs=ios
pkwftd7m2#