gpt4 book ai didi

android - 我怎样才能获得 MAC 地址 android 7.0

转载 作者:行者123 更新时间:2023-11-29 16:47:06 25 4
gpt4 key购买 nike

获取不到mac地址谁能帮帮我我是android开发的新手请帮助我 list .xml

    <receiver
android:name="com.example.v3rlu.authentification.DeviceAdmin"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/xml" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED" />
<action android:name="android.app.action.ACTION_DEVICE_ADMIN_DISABLED" />
</intent-filter>
</receiver>

启动 Activity 检查

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check);
mac=(TextView) findViewById(R.id.textView) ;
DeviceAdminReceiver admin = new DeviceAdminReceiver();
DevicePolicyManager devicepolicymanager =
admin.getManager(getApplicationContext());
ComponentName name1 = admin.getWho(getApplicationContext());
if (devicepolicymanager.isAdminActive(name1)){
mac_address = devicepolicymanager.getWifiMacAddress(name1);}

mac.setText(mac_address);
}}

对于 receiverclass 我从 android 网站得到了代码

最佳答案

试试这个。

public String getMacAddr() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
return "";
}

StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
//res1.append(Integer.toHexString(b & 0xFF) + ":");
res1.append(String.format("%02X:",b));
}

if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
}
return "";
}

在 list 中添加互联网权限

<uses-permission android:name="android.permission.INTERNET"/>

关于android - 我怎样才能获得 MAC 地址 android 7.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47607679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com