-
-
Save sergeioff/e953d6ef651cad86c400ac017db280a7 to your computer and use it in GitHub Desktop.
Check if device is low end.Low end= Low Memory || Bad Network
This file contains 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
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