Skip to content

Instantly share code, notes, and snippets.

@Ray33
Last active November 15, 2017 14:01
Show Gist options
  • Save Ray33/4c66d2b06b9b14c2170ac7e59f8f7b9e to your computer and use it in GitHub Desktop.
Save Ray33/4c66d2b06b9b14c2170ac7e59f8f7b9e to your computer and use it in GitHub Desktop.
Check if device is low end.Low end= Low Memory || Bad Network
private boolean getIsLowDevice(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
double availableMegs = (double)mi.availMem / 1048576d;
String networkType = getNetworkClass(context);
return "2G".equalsIgnoreCase(networkType) && availableMegs > 400;
}
public String getNetworkClass(Context context) {
TelephonyManager mTelephonyManager = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
int networkType = mTelephonyManager.getNetworkType();
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN:
return "2G";
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_HSPAP:
return "3G";
case TelephonyManager.NETWORK_TYPE_LTE:
return "4G";
default:
return "Unknown";
}
}
@sergeioff
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment