怎么在手机上知道自己的网络ssid,手机怎么看已连接网络的ssid

首页 > 实用技巧 > 作者:YD1662023-11-23 00:06:36

首先要在AndroidManifest.xml加上权限:

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

安卓6.0模拟器上,有效的代码:

private String getWifiSSID() { String ssid = ""; try { ConnectivityManager connManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); assert connManager != null; NetworkInfo networkInfo = connManager.getActiveNetworkInfo(); if (networkInfo.isConnected()) { if (networkInfo.getExtraInfo() != null) { ssid = networkInfo.getExtraInfo().replace("\"", ""); } } } catch (Exception e) {} finally { return ssid; } }

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.