When is the intent ACTION_DEVICE_STORAGE_LOW broadcasted?

前端 未结 1 1484
南方客
南方客 2020-12-08 23:41

In my application, I have registered a broadcast receiver to receive the system intent ACTION_DEVICE_STORAGE_LOW. I was expecting this to be broadcasted whenever the phone h

相关标签:
1条回答
  • 2020-12-09 00:20

    TL;DR

    As long as the device maker doesn't change the default settings, the intent will be broadcast when the free memory reaches 10% of the internal device memory.

    Long Version

    I grepped through the Android source code for that intent and I got to a class called DeviceStorageMonitorService

    (located at: frameworks/base/services/java/com/android/server/DeviceStorageMonitorService.java)

    From the javadoc:

    This class implements a service to monitor the amount of disk
    storage space on the device. If the free storage on device is less
    than a tunable threshold value (a secure settings parameter; default 10%) a low memory notification is displayed to alert the user. If the user clicks on the low memory notification the Application Manager application gets launched to let the user free storage space.

    So there you have it. As long as the device maker doesn't change that, it will be at 10%.

    Checking out the source code a bit more, the DeviceStorageMonitor sends out a sticky Broadcast: (line 354)

    mContext.sendStickyBroadcast(mStorageLowIntent);
    

    Which means that even after the broadcast is finished you can catch the data by registering a receiver on that intent.

    from Android Developer - Context :

    Perform a sendBroadcast(Intent) that is "sticky," meaning the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent).

    hope this helps.

    0 讨论(0)
提交回复
热议问题