简体   繁体   English

连接到特定网络 - Android 10 - Java

[英]Connecting to specific network - Android 10 - Java

I'm developing an app which needs to connect to a specific wifi network with internet capabilities.我正在开发一个应用程序,它需要连接到具有互联网功能的特定 wifi 网络。 My app targets Android 10 devices and I'm writting it in java.我的应用面向 Android 10 设备,我用 java 编写它。 I took inspiration from this post: https://blog.ostebaronen.dk/2019/11/android-10-wifi.html (Thanks @Cheesebaron).我从这篇文章中获得灵感: https ://blog.ostebaronen.dk/2019/11/android-10-wifi.html(感谢@Cheesebaron)。

I can't find a suitable java translation (line or set of lines in java programming language) for the next line我无法为下一行找到合适的 java 翻译(java 编程语言中的一行或一组行)

NetworkAvailable?.Invoke(network);

which connects the device.连接设备。 The Invoke method is called in the OnAvailable method. Invoke 方法在 OnAvailable 方法中调用。

final ConnectivityManager.NetworkCallback networkCallback =
        new ConnectivityManager.NetworkCallback() {
            @Override
            public void onAvailable(@NonNull Network network) {
                super.onAvailable(network);
                // connect to network
                Log.i(TAG, "Connected to network with WIFI capabilities");
            }
            ...
        };

(I've include the necessary permissions in android manifest) (我已经在 android manifest 中包含了必要的权限)

Accoording to this comment: Android Q, programmatically connect to different WiFi AP for internet根据此评论: Android Q,以编程方式连接到不同的 WiFi AP 上网

If I need internet capabilities, a WifiNetworkSuggestion is required如果我需要互联网功能,则需要 WifiNetworkSuggestion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM