android - ActivityManagerCompat.isLowRamDevice 没用,总是返回 false

标签 android activity-manager

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

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

难怪它在我的 Android 4.0.4 设备上总是返回 false。但对我来说,这完全没有意义。还是我遗漏了什么?

最佳答案

So no wonder it always returns false

它并不总是返回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"));
}

(来自 the ActivityManager source code)

据我所知,低 RAM 设备大多是 Android One设备。根据您获得设备的位置,您可能不会遇到其中任何一种设备。

关于android - ActivityManagerCompat.isLowRamDevice 没用,总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39036411/

相关文章:

android - 如何将图片上传到从图库中选择的服务器?

java - Android:Facebook 登录和注销

android - 我可以通过调用另一个类的方法将新列动态添加到 sqlite 表吗?

android - ActivityManager.getRunningTasks 已弃用 android

android - 为什么 getRunningTasks 没有将RecentApplicationsActivity 识别为正在运行的任务?

javascript - 使用phonegap将文件下载到下载文件夹ios/android

java - 我无法将 Android 应用程序安装到手机上

Android:如何确定 IntentService 是否正在运行?

java - Android应用程序进程运行一段时间后自动终止