Prioritize WIFI connection instead Cellular data - android

We are developing an application that connects to an external device using WIFI, but this external device has no internet access.
In Android M we have realized that the System prioritize a connection with internet access, so the device uses Cellular data to connect internet instead of WIFI.
The problem in that behaviour is that we are not able to access the external device due the device is connected via cellular data instead of WIFI.
Is there anyway to prioritize Wifi connection over cellular data?
Thanks in advance.

I think this is what you are looking for : http://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network)
And here is similar problem, just the other way around :
How to use data connection instead of WIFI when both are enabled?

Related

ANDROID - Using wifi interface (no internet) for network call while connected with mobile data (internet)

I am working with android device for POS system. I need to do data backup by uploading data to portable 4G router with tf card. In my device, I am getting internet from mobile data. There is no internet in my portable 4G router. I am only using it for backup purpose since my device doesn't have sd card slot.
Ok please don't suggest anything other than my question. This is the proof of concept i need to prepared. Other alternative, my colleague and I are already brainstorming.
DEVICE INFO
connected with mobile data (have internet)
connected with wifi (no internet)
GOAL
to use wifi interface to upload data from device.
PROBLEM
network call only using network interface with internet. In my case mobile data. I have no idea how to use wifi interface to make network call instead of using mobile data interface.
IMPORTANT
device must always connected with mobile data and wifi
cannot put sim card to wifi router. This is to prevent portable 4G router from being used as hotspot after working hours.

Get Internet Access on a Android device from a smartphone without hotspot

I have an Android device that has wifi and Bluetooth modules. I want to build applications to connect the device to the internet using a smartphone's data connection. Is this possible?
The smartphone will have wifi as well as data connection. Can the smartphone's data connection be shared through Bluetooth? Or is there better alternatives like wifi-direct or NFC? I am aware that enabling Hotspot on the smartphone is an option. But with hotspot, the issue of wifi being turned off makes it not usable for my use case. Is there any alternative to wifi-hotspot?
What will be the best option for this and what things should I consider when building my applications and services?
NFC is definitely not the answer, the data rate is far too slow and the connection unreliable and the OS does not allow it.
You might be better with a USB ethernet adapter if your phone support USB On The Go (OTG)
Your phone should already support sharing a data connection using Bluetooth. This is called Bluetooth tethering. But you also have wifi, so wifi tethering is also an option to share your data connection. No additional app is required.

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!

How do I force Android to use wifi network instead of mobile network

I have a use case where I need to use Wifi network for my requests instead of the mobile network. The mobile device has already connected to the Wifi network. But Android seems to always resolve network requests using the mobile data network instead of the Wifi network. Note that the Wifi network does not have internet access, it is simply a wifi access point exposed by an external device during setup.
I tried using ConnectivityManager's setNetworkPreference(ConnectivityManager.TYPE_WIFI) but that did not work.
Disable mobile data while wifi setup is required.
It won't resolve any requests with a carrier network if this is enabled.
Enable aeroplane mode, then toggle wifi

Is it possible to access 3G Data Connection in Android?

I am developing an android application in which i want to turn off/on 3G. I have some doubts.
Is it possible to programmatically access 3G data connection?
If it is possible, how to turn off/on 3G data connection without accessing other data connections like 2G etc...?
Is 3G and wifi works at same time?
Which are the different data connections available in android?
Thanks in Advance
There is an unofficial way to turn on/off 3g via reflection. It is not guaranteed to work on all phones so be aware of this. See this answer:
https://stackoverflow.com/a/12535246/1369222
This will not control 3g and 2g separately. This will turn on/off the entire data connection.
Wifi and 3g are not simultaneously connect at the same time. Usually, Wifi is given preference over 3g and the data switches to 3g is wifi connection is lost/unavailable.
The number and types of connections available differs from phone to phone. But most of them do support 2g/3g/wifi.

Categories

Resources