yosefk

yosefk

Creating Hotspot network - it registers the I/F in NetworkInterfaces but it does not in ConnectivityManager

I’m creating Hotspot network in Android by
WifiManager.startLocalOnlyHotspot. It register the I/F in NetworkInterfaces but it does not in ConnectivityManager.
I need to bind DatagramSocket to hotspot interface by ConnectivityManager network, but associate the two.

Most Liked

premsinghsodha7

premsinghsodha7

Are you running the socket on the phone hosting the hotspot, or on a client connected to it? The distinction matters here.

A NetworkInterface is an OS interface; it is not itself an android.net.Network that you can pass to Network.bindSocket(). Finding the hotspot interface in NetworkInterface.getNetworkInterfaces() therefore does not supply the missing Network object.

If this is a UDP server on the hosting phone, first test ordinary unicast traffic from a connected client. You can bind a DatagramSocket to a local address and port using InetSocketAddress; that is different from binding the socket to an Android Network. Use an address actually assigned to the hotspot interface, rather than assuming an interface name or a fixed IP. Local-address binding is not a general replacement for Android network selection, so confirm packet delivery on the affected device.

If this is the client, use the Wi-Fi Network delivered through the appropriate connectivity callback, and bind the socket before connecting it.

Could you share your Android version, which side runs this code, and whether the traffic is unicast, broadcast, or multicast? Those cases need different handling.

References: local-only hotspots, DatagramSocket address binding, Network socket binding.

Where Next?

Popular Android topics Top

CristianM92
Hi, I’m working on an app who make the conversion between decimal degrees and degrees minutes seconds. I have to make an “Export” button ...
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
ciger
I want to get a clone of Instagram APK But with a difference I want to define in this clone that, for example, it is not possible to acc...
New
tunelabguy
I have an expensive app ($160) in the Play Store that I would like to update. I would like to do a beta test of the update with potentia...
New
sabibo
We recently switched some machines to a network that uses ipV6. Those machines are now unable to package our Unreal game for Android, du...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
Garrett
I’m stuck trying to understand how to get a variable initialised, and later updated, in kotlin to update in Jetpack Compose and cause a c...
New
paulo500
Can anyone help? I have an android projector with Google-licensed Android system loaded. It has the developer options passworded and th...
New
DuendeMartin
My Android Studio emulator is stuck on this loading screen. What’s going on?
New
deveshpatel-TW
I’m currently experimenting with Android Studio for a project that consists of multiple independent Android Library modules that internal...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
PragmaticBookshelf
A masterclass in the fundamentals and principles of functional programming. Minh Quang Tran The Art of Functional Programming is a ma...
New
PragmaticBookshelf
An illustrated guide to understanding and effectively using regular expressions. Staffan Nöteberg To effectively use regular expressi...
New