HOW CAN I MONITOR FOR CHANGES TO MOBILE DATA BEING ENABLED ON ANDROID?

naomi burke

Total Post:28

Points:196
Posted by  naomi burke
 648  View(s)
Ratings:
Rate this:
How can I monitor for changes to mobile data being enabled on Android?
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: How can I monitor for changes to mobile data being enabled on Android?

    You can use OnNetworkActiveListener to monitor activation of network data. The ConnectivityManager class can give you infos on the currently active network connection. It would go like this :

    ConnectivityManager cm = getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfos networkInfos = cm.getActiveNetworkInfo();
    if(networkInfos.isConnected()){
        //Do something
    } else {
        //Do something else
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!