ActivityManagerCompat.isLowRamDevice没用,总是返回false

Jen*_*sen 2 android activity-manager

我想isLowRamDevice为我的应用程序使用帮助方法,它可以流式传输视频.当我支持设备关闭API级别15时,我不得不使用ActivityManagerCompat.isLowRamDevice().我真的很困惑,它总是返回假,即使我使用非常旧的设备.然后我检查了方法本身并看到了这个:

    public static boolean isLowRamDevice(@NonNull ActivityManager am) {
        if (Build.VERSION.SDK_INT >= 19) {
            return ActivityManagerCompatKitKat.isLowRamDevice(am);
        }
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

所以难怪它总是在我的Android 4.0.4设备上返回false.但对我来说,这绝对没有意义.或者我错过了什么?

Com*_*are 6

所以难怪它总是返回错误

它并不总是回归false.

在运行Android 4.3或更早版本的设备上,它将始终返回false.那是因为当时不存在作为低RAM设备的系统标志.

在运行Android 4.4或更高版本的设备上,它将返回系统标志的值,以确定这是否是低RAM设备:

/**
 * Returns true if this is a low-RAM device.  Exactly whether a device is low-RAM
 * is ultimately up to the device configuration, but currently it generally means
 * something in the class of a 512MB device with about a 800x480 or less screen.
 * This is mostly intended to be used by apps to determine whether they should turn
 * off certain features that require more RAM.
 */
public boolean isLowRamDevice() {
    return isLowRamDeviceStatic();
}

/** @hide */
public static boolean isLowRamDeviceStatic() {
    return "true".equals(SystemProperties.get("ro.config.low_ram", "false"));
}
Run Code Online (Sandbox Code Playgroud)

(从ActivityManager源代码)

AFAIK,低RAM设备大多是Android One设备.根据您获得设备的位置,您可能不会遇到其中之一.