简体   繁体   English

如何在android studio的textview中显示用户的Android Mac地址

[英]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.

相关问题 如何在android上的textview上显示mac地址? - How to display mac address on textview on android? ANDROID-如何在android studio中将数据库mysql php的值显示为textview - ANDROID - How to display value of database mysql php into textview in android studio 如何使Android Studio在textView中显示计算的值 - How do I get Android Studio to display the value of a calculation in a textView Android Studio,如何从Sqlite数据库中检索数据并将其显示到textview中? - Android Studio, how to retrieve data from Sqlite database and display it into textview? 如何在 function 中使用 textview Android Studio 在 Z93F725A074233FEC889ZDF48 中显示文本 - How can I display text in a function with textview Android Studio in java 如何显示计算结果以在Android Studio / Java中显示提示的TextView? - How to display calculations result in a hinted TextView in Android Studio/Java? 如何将 integer 从 firebase firestore 显示到 Android Studio 的 TextView? - How to display integer from firebase firestore to Android Studio's TextView? 显示号码 android studio中textview中的recyclerview项目 - Display no. of items of a recyclerview in a textview in android studio 如何在 Android 的 TextView 中显示计时器? - How to display a timer in a TextView in Android? ANDROID - 如何将JSONArray显示到textview中 - ANDROID - how to display JSONArray into textview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM