简体   繁体   中英

Connecting to specific network - Android 10 - Java

I'm developing an app which needs to connect to a specific wifi network with internet capabilities. My app targets Android 10 devices and I'm writting it in java. I took inspiration from this post: https://blog.ostebaronen.dk/2019/11/android-10-wifi.html (Thanks @Cheesebaron).

I can't find a suitable java translation (line or set of lines in java programming language) for the next line

NetworkAvailable?.Invoke(network);

which connects the device. The Invoke method is called in the OnAvailable method.

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)

Accoording to this comment: Android Q, programmatically connect to different WiFi AP for internet

If I need internet capabilities, a WifiNetworkSuggestion is required

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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