Properly route non internet Wifi sockets & Cellular Internet request (Android L & M) - android

Is it possible to dedicate a WiFi network (to a device with no internet access) to a socket in an app and keep Cellular network as the default internet connection for the Android device (and other network requests from the app)? (Android 5 & 6)
I can easily switch between WiFi and Cellular within the app but the main issue is when WiFi is up, Internet is not accessible anymore for the app and all apps already running on the device (i.e. streaming music, web browser, ...)
I have tried to bind the Wifi network to the process or a socket but I can't find any way to do that with getting the network active (and at this point Android just try to route all the internet traffic to the device...).
My understanding is that Android 5 & 6 provides more flexibility to route traffic to multiple networks at the same time but I think I'm missing something here...

As per the Connecting your App to a Wi-Fi Device blog post:
Alternatively, if you’d like to route some of your app traffic to the Wi-Fi device and some to the Internet over the mobile network:
For HTTP requests you can use Network#openConnection(java.net.URL), directly routing your request to this network.
For low-level socket communication, open a socket and call Network#bindSocket(java.net.Socket), or alternatively use Network#getSocketFactory.

Related

Accessing Website On Offline Network With Android 11+

I have a webserver that is running on a network that is not connected to the internet.
The webserver serves up a website.
When I connect an android phone to it, I am able to run the website that is on the webserver
But with certain phones that are running Android 11 I need to disable the mobile data on the phone before it will try to access the website over wifi. It seems the phone will not try to request the url on the wifi network because it doesn't have internet, so it defaults to using the 4G/5G Cellular internet connection. This is too bad, because I would like the phone to use the wifi connection.
I would think that perhaops I could "force" the phone to use the wifi connection by typing the IP address in the browser's URL bar (eg. http://192.168.211.1/index.php), however it seems that even with the "local ip" it will still try to use the 4G/5G network instead of the "offline wifi" network.
The only workaround I have found is to disable moblie data on the phone, but this is not ideal.
I would think that some IoT devices would have an offline webserver used for configuation/control.
Is there a certain port or settings I should be using?
Is there a designated port that the browser/OS would expect to be on an offline network?
Basically, how can I make the phone use the wifi, even though the wifi is not connected to the internet?
Thanks so much for any pointers!

Connecting Android to multiple network interfaces (WiFi/4G and bluetooth PAN)

I am writing an app which I want to connect to a closed (no internet access) bluetooth PAN to access a local data server. When connecting to the PAN I want the user to still have internet access via their existing 4G/WiFi data connection.
I have set up DNSMasq on the PAN gateway and have configured the dns options to not provide a gateway/DNS server for the interface.
Using reflection I can connect a phone to the PAN but the phone then drops any other network connections.
With the new Android api's (NetworkBuilder & ConnectivityManager.requestNetwork) I can request a WiFi connection before connecting to the PAN and the phone will keep both connections up. The problem is that other apps on the phone still do not have internet access. It would appear that the device is adding a default route for the bt-pan interface, even though dhcp has not provided a router option (confirmed via Wireshark).
Is it possible to connect to a network without setting a default gateway so other apps will continue to use 4G/WiFi interface?

Use 3G for internet and WiFi for LAN in android

I am developing an android app to stream movies from local server on a WiFi. The WiFi does not have internet, it will be used only for accessing the streaming server.
What would make the app kickass is that the app users can continue using internet on their 3G while connected to my WiFi and streaming the movie.
I know for a fact that when android connects to a WIFI, the phone under the hood makes a call to clients.google.com/generate_204 to check if internet is available on the WIFI. If it receives no response, it continues using 3G along with being connected to the WiFi. However, in this scenario if my app makes a request to say 192.168.24.5 (ip address of my streaming server), it does not use WiFi to reach this ip but hunts for this address on 3G and fails.
What i need to achieve is that when android is connected to both my wifi and 3G, any call to private ip is directed to WiFi whereas any call to internet should use 3G.
Can this be done and how?

Android OS Wi-Fi network management

Does the Android OS manage networks so that it's connected to the most ideal one? I have an app that is hard-coded to connect to a local network that has no internet access but as soon as it connects to the network it then switches back to my home's WiFi (which has internet connection). If I make the OS 'Forget' my home network I don't get this see this issue but that isn't exactly a practical solution.

Can we connect to iPhone from Android device even though not in the same network?

I am working around wifi direct and NSD (Network Service Discovery) to transfer files.
NSD: where serivce has been created and can scan the other devices which are publishing the same service with in the same network.
WiFi Direct: This is used to scan the near by devices without network
WiFi P2P Network Serice Discovery: This is used scan the service near by devices where other devices provide the same service (NSD+WiFi Direct)
As per requirement, I need to give compatibilty to iOS device even though both are not in same network. I came to know that NSD is similar to Bonjour service by iOS.But this can be possible when devices are in the same network.
Is there any way to get connect to iPhone when both are not in same not network?
Ignoring the intricacies of getting Android and iOS to play nice together, it is possible to make them think they are in the same network without physically being there. If I understand you correctly, seems like you have two options:
Setup up a VPN server in network A and the device in network B connect to it. This would make the device in network B think it was on network A, and have access to all LAN services (such as NSD).
Set up VLAN trunking on a switch and put network A in the same network as B.
Option 2 would only work if they were geographically in the same area (like on the same campus). Option 1 would be preferable if they were geographically disparate, or you were unable or unwilling to make the infrastructure changes necessary to support option 2.

Categories

Resources