NetworkInfo instantiation
Date : March 29 2020, 07:55 AM
wish help you to fix your issue This constructor is hide. You can't instanciate it normally, but I think you can use reflection to use it. From the source code /**
* @hide
*/
public NetworkInfo(int type, int subtype, String typeName, String subtypeName)
|
NetworkInfo Reflection
Date : March 29 2020, 07:55 AM
hop of those help? You are using the the getConstructor correctly. I think you just don't have compatible versions of android SDK. The javadoc for NetworkInfo doesn't show any constructors.
|
Difference between NetworkInfo.isConnected() and NetworkInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED.
Tag : java , By : Gabriel
Date : March 29 2020, 07:55 AM
hope this fix your issue So if we look at the source code of NetworkInfo.java class you will see that the network detailed states are declared as Enum, public enum DetailedState {
/** Ready to start data connection setup. */
IDLE,
/** Searching for an available access point. */
SCANNING,
/** Currently setting up data connection. */
CONNECTING,
/** Network link established, performing authentication. */
AUTHENTICATING,
/** Awaiting response from DHCP server in order to assign IP address information. */
OBTAINING_IPADDR,
/** IP traffic should be available. */
CONNECTED,
/** IP traffic is suspended */
SUSPENDED,
/** Currently tearing down data connection. */
DISCONNECTING,
/** IP traffic not available. */
DISCONNECTED,
/** Attempt to connect failed. */
FAILED,
/** Access to this network is blocked. */
BLOCKED,
/** Link has poor connectivity. */
VERIFYING_POOR_LINK,
/** Checking if network is a captive portal */
CAPTIVE_PORTAL_CHECK
}
public boolean isConnected() {
synchronized (this) {
return mState == State.CONNECTED;
}
}
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
|
ConnectivityManager.getActiveNetworkInfo() / NetworkInfo is deprecated in API 29. What's an alternative?
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Seem like whole NetworkInfo is deprecated on API 29. , The solution is this: val capability = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
return capability?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ?: false
|
NetworkInfo for VPN on Android API 21+
Date : March 29 2020, 07:55 AM
|