In some devices(device may or may not be rooted device) we have an option for restricting wifi and mobile data.
How can I check programmatically the device restricted internet connection?
Asked
Active
Viewed 424 times
-2

Sanal
- 418
- 6
- 17
-
4Possible duplicate of [How to get Any Application Background data Usage Status in Android](https://stackoverflow.com/questions/17802374/how-to-get-any-application-background-data-usage-status-in-android) – Jakub Gabčo Nov 20 '17 at 12:39
-
1@JakubGabčo you're right if he wants exactly the status. this is only possible with root access. however the online check is possible as you can see in my answer – Sebastian Schneider Nov 20 '17 at 12:41
-
@Jakub Gabčo thanks for your input but in my case device may or may not be rooted, what am looking for a common solution. – Sanal Nov 22 '17 at 05:04
-
1Impossible unrooted – Sebastian Schneider Nov 22 '17 at 09:38
1 Answers
-2
Out of my utils class:
/**
* Check if the device is connected to the internet.
*
* @param context the application context
* @return boolean if device is online
*/
public static boolean isOnline(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
ConnectivityManager
is supposed to report null when you are not allowed to do work in the background or are not allowed to connect to the internet.

Sebastian Schneider
- 4,896
- 3
- 20
- 47
-
This method will return boolean based on internet ON or OFF. I want to programmatically detect internet restricted is enabled or not. – Sanal Nov 22 '17 at 05:09
-