Questions tagged [android-connectivitymanager]

159 questions
2
votes
4 answers

Android API 29 - check if connected to the cellular network

I am developing an SMS app and want to check for network (cellular) connection. With API level 29, checking for connection requires use of ConnectivityManager.NetworkCallback. What I have managed is to get 'onAvailable()` to inform me when a network…
SimpleOne
  • 1,066
  • 3
  • 12
  • 29
2
votes
1 answer

Perform network-specific host name resolutions using Network.getAllByName

In the ConnectivityManager documentation, in bindProcessToNetwork javadoc, there is the following comment : Using individually bound Sockets created by Network.getSocketFactory().createSocket() and performing network-specific host name…
Mathieu H.
  • 800
  • 8
  • 21
2
votes
2 answers

if mobile data is on and wifi is also on but does not have data.then how to send request by WIFI

Use this code if you want to use only Wifi. Please ensure that android version should be greater then 21. @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static void stayOnWifi(Context context) { final ConnectivityManager…
Amar
  • 87
  • 7
2
votes
1 answer

bindProcessToNetwork is not working with ffmpeg in android

I am using FFmpeg to re stream video from a camera(which is connected via wifi with no internet connection) to another server, and I want to do the re streaming process via cellular data. As I am already connected to wifi and to use cellular data…
2
votes
0 answers

Android wifiManager.enableNetwork(j.networkId, true) is switching back to previous network

I have to show list of access points (with no internet) and then connect to a selected network. I was able to get all available network network with wifiManager.getScanResults() then i have filtered my preferred open network and configured with…
2
votes
3 answers

Android Internet Connection timeout

I'm able to detect Internet connection using public class InternetDetector { private Context _context; public InternetDetector(Context context) { this._context = context; } /** * Checking for all possible internet…
2
votes
3 answers

Proper way to check if Wifi is connected in android

For my app, I need to make sure the user is connected to wifi before contact with the server. I have found two methods to do so, but I am not sure if one suffices. First I am adding this: WifiManager wifiManager = (WifiManager)…
2
votes
7 answers

Check internet connection in android (not network connection)

I have a problem with checking internet connection in android at runtime. I use some different methods to check internet connection but i don't know which one is better . because each of them have some problems . Method 1 check internet connection…
2
votes
3 answers

How to use mobile data forcefully for any application when wifi is on in Android 6

I want the android application to use only mobile data even if WIFI and mobile data both on in Android 6. How can I bind the android process to Mobile data only. Please suggest. Examples will be good.
2
votes
2 answers

How to handle com.android.volley.NoConnectionError: java.net.UnknownHostException

I am using Volley for webcalls in my application and everything is working fine and smooth except one state in which somehow my device is not getting Network Connection but checking connection via code is returning true using below code. public…
2
votes
2 answers

What will be the context for CONNECTIVITY_SERVICE in Fragment?

What will be the context for CONNECTIVITY_SERVICE in a Fragment? I have checked getActivity also but it is giving an error. public boolean isOnline() { ConnectivityManager connectionManager = (ConnectivityManager) …
1
vote
3 answers

ConnectivityManager Callback Memory Leak - Android

I'm using LeakCanary and it found a memory leak in ConnectivityManager. I've never used ConnectivityManager before and it's not in my project from anything that I wrote. I'm assuming maybe a 3rd party library is using it. How can I fix this? ┬─── │…
1
vote
0 answers

Android 13- Unable to connect with WiFi netork after few attempts

User is unable to connect with Wi-Fi network initially, but after few attempts we are getting "No devices found. Make sure devices are turned on and available to connect." WifiNetworkSpecifier wifiNetworkSpecifier = new…
1
vote
1 answer

Callback for ConnectivityManager not working in BlueStacks 5 emulator

In order to get notified when the device connects/disconnects from internet, I took the following approach: ConnectivityManager connectivityManager = activity.getSystemService(ConnectivityManager.class); …
1
vote
2 answers

How to check the connection status in Android avoiding StrictMode

I created a function that returns a boolean based on the presence of an internet connection, this function it is called different times from different java classes. The only way that I find to use it is to use the StrictMode.setThreadPolicy (i know…