Reputation: 13
I want to check the mobile data connection and if it turns on or off, I will define an event for it. When the data cell is turned on, display the mobile data icon, When the mobile data is turned off, the mobile data icon will also be hidden!
Upvotes: 0
Views: 106
Reputation: 3401
Determine whether you have an internet connection
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
Determine the type of internet connection
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isMetered = cm.isActiveNetworkMetered();
For more information click here.
Upvotes: 0