1

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)

  • What do you mean "java translation"? Translation from what? What do you mean by "connecting to a specific network"? Do you mean a Wifi connection? Do you mean a VPN connection? – m0skit0 Jul 26 '21 at 15:33
  • By java translation I mean a line in java programming language. By connecting to a specific network I mean connecting to a specific wifi network with internet capabilities. I'll edit the post, thanks for suggesting them – Delfina Martin Jul 26 '21 at 15:36
  • Ok, I didn't check the link you mentioned, sorry. You want a translation from C#. NetworkAvailable is an Action; in Java this corresponds to [a lambda expression](https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html). – m0skit0 Jul 26 '21 at 15:45
  • I see. But is there a way to connect the device directly to the only network I specified (skipping the UI)? – Delfina Martin Jul 26 '21 at 15:50

1 Answers1

1

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

If I need internet capabilities, a WifiNetworkSuggestion is required