Should my Android phone automatically select wi-fi if available, if not then go to the next data service etc. If I use
connectivity.setNetworkPreference(ConnectivityManager.TYPE_WIFI);
will that ensure the same result or confine it to using wi-fi only.
Yes. By default android chooses WiFi network and if WiFi network is not available then it switches to mobile carrier network. To implement switch form WiFi to mobile network you can follow my answer over here: How to handle WiFi to Mobile network switch programatically?
If the Device is connected to a WIFI network will Android use that because it has 1. priority.
And you will almost always prefer using WIFI to your network operations. So you dont really have to worry about this.
I could see on my different devices (all HTC I have to say), under Android 2.1 and 2.2: when both 3G and Wifi are both enabled and available, the system switches down the 3G to prefer the Wi-fi.
The documentation says "When active, all data traffic will use this connection by default. " Whichever you set as your network preference, that will be made the default connection. The system default must be Wifi itself.
Related
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.
There are lots of post on SO regarding setting up AP (Hotspot) on android mobile. However, in all these cases, the AP is a conduit to the outside internet world. In my case, I just want a server application running over a mobile setup as an AP. And let all the client android mobiles connect to it, send their data and disconnect if they like. No internet connection is assumed (i.e, no gprs/3g etc).
My observations: If I setup a wifi AP (via settings -> tethering and portable hotspots) when it is also connected to GPRS, then another android phone can successfully connect to this AP and send the data to the application. However, if I disable the GPRS, even though the client shows that it is connected to the AP, it can't seem to send any data. It seems that an external internet connection is a necessity for the AP mode to work.
Is this understanding correct? Or am I setting something wrong?
I know that I am late to the party (more than 3 years late :) but I was searching for a solution to this problem and stumbled upon an easy workaround. I am using a Nexus 4 with Android 5.0.1 and I can easily configure my phone to use it as an Android Wi-fi AP hotspot - without internet. Just go to Settings / Data Usage and disable "Mobile data" option under the Mobile tab. Then enable the WiFi hotspot option as usual.
I was trying to get this working in order to play with a VirtualBox machine from VulnHub.com that asked for a Bridged Connection when I was commuting to work (no Internet, but with my laptop and my mobile phone I was able to make it :)
I think you have used the internet IPs in your code not the local IPs for communications,is'nt it?
I have the same use case and was looking for the same info as you are. I checked that some of the WiFi-only tablets do not even have a HotSpot setting. Even the devices that do have it, if I remove the SIM card, I cannot enable the HotSpot (I get a message asking me to insert a SIM first).
It looks like our use case is not supported by Android. Rather, the HotSpot feature was not designed with our use-case in mind. I mean, why would an end-user want to use an Android phone or tablet in a HotSpot mode if it didn't also provide outside connectivity?
Since I don't have an Android 4.0 device I haven't been able to test this myself. Also I wonder if connecting device A (a smartphone) to device B (a wifi direct capable device) using Wifi direct would mean that device A would assume it is provided with internet from device B (tethering?). I am trying to make an application for device A that would communicate with a device B that does NOT provide internet, thus it would be interesting to know if such a scenario would lead to device A losing internet connectivity for the duration of the connection. Is the situation different depending on if device A is connected to internet through an AP or through 3G/4G?
Perhaps using Bluetooth would be a solution, but in my case security is an issue, and it seems to me that Wifi direct provides stronger security (WPA2).
Any info would be helpful!
/S
On Android, Wi-Fi Direct doesn't interfere with your connection to the Internet (Wi-Fi or 3G/4G). A problem may be that once your turn on the Wi-Fi (to enable Wi-Fi Direct, your phone will try to connect to one of the saved available networks and will disable your 3G connection. That is because Android (by default) doesn't support dual connection (via both Wi-Fi and 3G/4G), but there is some applications around that claim that they can provide such functionality.
I'm curious is there any way in Android, so I can set my application to use 3G network or not to do it. If 3G is not allowed I need my application to use only Wifi even if there is no available Wifi network.
You can use WifiManager::getConnectionInfo to get info if wifi is connected or not before you make any network calls.
Does anyone knows if the wifi networks for android phones are based on Access Point Names (APN) ? I ask because in my android application I plan to overwrite some fields in all APN's to disable cellular network, but I still want to have available the wifi for the user
AFAIK, WiFi is independent from APN settings, i.e., if you mess with the APN settings WiFi will still work (cf. the APNdroid application).