如何获取Android Pie(9)设备中的当前WiFi连接名称? [英] How to get current wifi connection name in android pie(9) devices?

查看:370
本文介绍了如何获取Android Pie(9)设备中的当前WiFi连接名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这对您来说非常简单.在这里,我只是试图在android pie设备中获得WiFi名称.在下面的代码行的帮助下,我可以获得Nogout设备的WiFi名称.

I know it is very simple for you. Here I am just tried to get WiFi name in android pie devices. I am able to get WiFi name till Nogout devices with the help of below line of code.

 String ssid = wifiInfo.getSSID();

我尝试了很多答案和Android开发人员文档,但不幸的是,我无法在手机(诺基亚6.1及更高版本)上获得WiFi名称.我知道我在犯错误.

I have tried lots of answer and Android developer docs but unfortunately, I can not get a WiFi name on my mobile(Nokia 6.1 plus). I Know I am doing mistakes.

我只想要一个代码,就可以从手机到android studio logcat获得一个wifi名称.

I just want a code there I can get a wifi name from my mobile to my android studio logcat.

推荐答案

这与权限相关.由于API级别为27,因此您需要ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATION权限.您可能还需要Android 9的CHANGE_WIFI_STATE(无论如何,按照Google

This is related to permissions....since API level 27 you need either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission. You may also need CHANGE_WIFI_STATE for Android 9 (that's the case for wifi scan anyway as per google permisson model

然后尝试此代码

   ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (networkInfo.isConnected()) {
            WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            wifiInfo.getSSID();
            String name = networkInfo.getExtraInfo();
            String ssid = "\"" + wifiInfo.getSSID() + "\"";
}

这篇关于如何获取Android Pie(9)设备中的当前WiFi连接名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆