安卓手机中的MAC地址



我用 Android Studio 和 Java 构建了一个 android 应用程序,我想从手机上获取 mac 地址 限制用户执行任何操作和其他操作 谁能帮助我? 我的代码是这个,但没有工作

private void getmacadres() {
String macAddress =
android.provider.Settings.Secure.getString(this.getApplicationContext().getContentResolver(), "android_id");

Toast.makeText(G.Context, macAddress, Toast.LENGTH_LONG).show();
} 

将此权限添加到清单文件中:

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

并使用它:

WifiManager wifiManager = (WifiManager) 
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress(); 

我已经通过使用这个解决了这个问题

private String deviceId() {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}

最新更新