Android Enable/Disable Usage of 3G for my application - android

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.

Related

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

Prioritize WIFI connection instead Cellular data

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?

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.

Connect to 802.1x WiFi with an NFC tag

I am trying to write NFC tags to be able to connect Android devices automatically to a WiFi network that has 802.1x network-based security. I can do this easily with WEP, WPA, and WPA2-secured WiFi networks, but is it possible to do this for 802.1x? If so, how do I do it? Also, I am pretty sure I am misunderstanding 802.1x completely.

android which data connection

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.

Categories

Resources