Android 10连接到特定的wifi但没有互联网连接

时间:2020-08-18 13:30:05

标签: android android-wifi android-10.0

我通过下面的代码连接到wifi,它可以成功连接但没有互联网连接(带有x的android show icon network),不知道为什么。

WifiNetworkSpecifier wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
    .setSsid(ssid)
    .setWpa2Passphrase(password)
    .build();

NetworkRequest networkRequest = new NetworkRequest.Builder()
        .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
        .setNetworkSpecifier(wifiNetworkSpecifier)
        .build();

connectivityManager = (ConnectivityManager)activity.getSystemService(Context.CONNECTIVITY_SERVICE);

networkCallback = new ConnectivityManager.NetworkCallback() {
    @Override
    public void onAvailable(@NonNull Network network) {
        super.onAvailable(network);
        connectivityManager.bindProcessToNetwork(network);
    }
};
connectivityManager.requestNetwork(networkRequest, networkCallback);

0 个答案:

没有答案