Created
June 30, 2018 18:22
-
-
Save MaksymKrut/709dc78df1ef2cfb7f3791ab451095f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.softalp.viner.utils; | |
import android.content.Context; | |
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.telephony.TelephonyManager; | |
public class NetworkType { | |
private Context context; | |
private boolean connected; | |
private String networkType; | |
private String networkSubType; | |
private int suggestedWaitTime; | |
private NetworkInfo activeNetwork; | |
public NetworkType(Context context) { | |
this.context = context; | |
defineNetworkType(); | |
} | |
private void defineNetworkType() { | |
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (connectivityManager != null) { | |
activeNetwork = connectivityManager.getActiveNetworkInfo(); | |
} | |
if (activeNetwork != null) { | |
setConnected(true); | |
setSuggestedWaitTime(1); | |
setNetworkSubType("mobile_fast"); | |
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { | |
setNetworkType("WiFi"); | |
setNetworkSubType("wifi_fast"); | |
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { | |
setNetworkType("Mobile"); | |
if (activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_UNKNOWN || | |
activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_1xRTT || | |
activeNetwork.getSubtype() == TelephonyManager.PHONE_TYPE_GSM || | |
activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS) { | |
setNetworkSubType("mobile_slow"); | |
setSuggestedWaitTime(8); | |
} else if (activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE || | |
activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_CDMA || | |
activeNetwork.getSubtype() == TelephonyManager.NETWORK_TYPE_UMTS) { | |
setNetworkSubType("mobile_medium"); | |
setSuggestedWaitTime(5); | |
} | |
} | |
} else { | |
setConnected(false); | |
} | |
// System.out.println("\n\n------ networkType.getSuggestedWaitTime() ------ : " + getSuggestedWaitTime() + "\n\n"); | |
// System.out.println("\n\n------ networkType.getNetworkType() ------ : " + getNetworkType() + "\n\n"); | |
// System.out.println("\n\n------ networkType.getNetworkSubType() ------ : " + getNetworkSubType() + "\n\n"); | |
} | |
public boolean isConnected() { | |
return connected; | |
} | |
public void setConnected(boolean connected) { | |
this.connected = connected; | |
} | |
public String getNetworkType() { | |
return networkType; | |
} | |
public void setNetworkType(String networkType) { | |
this.networkType = networkType; | |
} | |
public String getNetworkSubType() { | |
return networkSubType; | |
} | |
public void setNetworkSubType(String networkSubType) { | |
this.networkSubType = networkSubType; | |
} | |
public int getSuggestedWaitTime() { | |
return suggestedWaitTime; | |
} | |
public void setSuggestedWaitTime(int suggestedWaitTime) { | |
this.suggestedWaitTime = suggestedWaitTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment