Android 检查应用程序启动时存储 space 是否不足

Android Check if the storage space is low on app boot

我想我可以在广播接收器中使用 Intent.ACTION_DEVICE_STORAGE_LOW 在设备存储空间不足时通知我。 解释 here.

我知道我可以找出有多少 space 用户可用 here

但是,如果可能的话,我想避免设置 is/isn 不够 space 的边界。 OS 会在存储空间不足时向用户发出通知。

问题:如果 OS 认为可用的 space 不足,是否只在启动时显示应用内错误消息?

根据一些 related sample code from google 你可以走这条路:

IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;

换句话说,有一个 DeviceStorageMonitorService 服务在 OS 级别运行并检测到低存储情况。从那里,它发送一个粘性广播,任何 activity 或服务都可以稍后检查。在这个例子中,他们注册了一个空接收器作为测试粘性广播是否已发送的一种方式。