[英]How to display the users Android Mac Address in a textview on android studio
I'm new to android studio and was wondering if anyone knew how to obtain the users Mac address and display it in a text view with the tag lbl_Mac?我是 android studio 的新手,想知道是否有人知道如何获取用户的 Mac 地址并将其显示在带有标签 lbl_Mac 的文本视图中?
This is my text view xml这是我的文本视图 xml
<TextView
android:id="@+id/lbl_Mac"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="MAC Address: Not Found"
android:textColor="#FFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.989"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.983" />
and i want to use this code to obtain the MAC address:我想使用此代码来获取 MAC 地址:
public String getMacAddress(Context context) {
WifiManager wimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String macAddress = wimanager.getConnectionInfo().getMacAddress();
if (macAddress == null) {
macAddress = "Device don't have mac address or wi-fi is disabled";
}
return macAddress;
}
But I want to set the mac address to the text view.但是我想将mac地址设置为文本视图。
Just needed to add the public string name into the setText brackets.只需要将公共字符串名称添加到 setText 括号中。
lbl_Mac.setText(***getMacAddress***(this));
For Example例如
public String ***getMacAddress***(Context context) {
WifiManager wimanager = (WifiManager)
context.getSystemService(Context.WIFI_SERVICE);
String macAddress = wimanager.getConnectionInfo().getMacAddress();
if (macAddress == null) {
macAddress = "Device don't have mac address or wi-fi is disabled";
}
return macAddress;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.