androidtelevisioniptv

android IPTV box programming for launcher


I'm writing a iptv setup box launcher in android and I'm trying to find out the ethernet connectivity information(that whether user is connected with ethernet cable or not), Please help ... My apology if question is not clear. Please help i need it badly, stucked from last three days.


Solution

  • private Boolean isNetworkAvailable() {
            ConnectivityManager connectivityManager
                    = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
    }
    
    public Boolean isWifiConnected(){
            if(isNetworkAvailable()){
                ConnectivityManager cm
                        = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
            }
            return false;
    }
    
    public Boolean isEthernetConnected(){
            if(isNetworkAvailable()){
                ConnectivityManager cm
                        = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                return (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_ETHERNET);
            }
            return false;
    }
    

    Then :

    if(isEthernetConnected()){
        // connected
    }
    else {
        //not connected
    }