0

When I upload files,

  1. if the mobile data is ON, it uses the mobile data to transfer files.
  2. if the mobile data is OFF, the file transfer happens over the connected Wifi network.

The Issue is, I don't want the file transfer to happen using the mobile data, even when its in the ON state. The file size is too large for mobile data consumption.

Question 1 : Are there any steps I am missing from the following code that would help me prevent mobile data usage.

Question2 : If all steps are proper, then is there a way to disable mobile data when Wifi connection is established and enable it back when the Wifi connection is broken. (Enabling and disabling of mobile data using connectivity manager is deprecated, please suggest others/ latest solutions).

Question3 : Is there a better way of doing this without using Wifi-Direct.

  1. Set Up a Wifi Scan Intent, register a broad cast receiver to receive the scan results and then initiate the scan.

register broadcast receiver and scan Wifi.

  1. I get a list of available Wifi Networks.
  2. I connect to a specific Wifi using the WifiNetworkSpecifier with below code.

connect to Wifi with SSID and passphrase.

Other SO questions : Similar question, Question for hint.

  • 1
    Android will prefer WI-FI over cellular, meaning that if your device is currently not connected to a WI-FI network simply don't perform the action this way you can ensure it will never use your cellular data. – Robin Feb 28 '23 at 10:57

0 Answers0