Skip to content

Instantly share code, notes, and snippets.

@sergeioff
Forked from Ray33/IsDeviceLowEnd.java
Last active November 15, 2017 14:01
Show Gist options
  • Save sergeioff/e953d6ef651cad86c400ac017db280a7 to your computer and use it in GitHub Desktop.
Save sergeioff/e953d6ef651cad86c400ac017db280a7 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 / 0x100000L;
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";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment