5

I think I can use Intent.ACTION_DEVICE_STORAGE_LOW within a broadcast receiver to notify me when the device storage is low. Explained here.

I know that I could find out how much space the user has available here.

However, I want to avoid having to set a boundary of what is/isn't enough space available if possible. The OS gives the user a notification when the storage is low.

Question: Is there anyway of only showing an in app error message on boot if the OS thinks the space available is low?

Community
  • 1
  • 1
Jake Graham Arnold
  • 1,416
  • 2
  • 19
  • 40
  • Listen for the `ACTION_DEVICE_STORAGE_LOW` broadcast? "This is a protected intent that can only be sent by the system." but it will and should be fired by the device. – shkschneider Jun 18 '15 at 15:40
  • The solution that I was hoping for would be to do a check on start up, rather than at any point in the apps lifetime. The problem with a broadcast is it could come back at anytime. Reason I don't want this is because if the user is in the middle of doing something I don't want this interfering and ruining their user experience. – Jake Graham Arnold Jun 18 '15 at 15:48
  • If I can't do a check the fall back is just making my own check on startup... but I'm not sure how much space available counts as "too low" so I was hoping I could get the OS to decide for me. – Jake Graham Arnold Jun 18 '15 at 15:50
  • Then you just need to catch `BOOT_COMPLETED` broadcast and run your check code. Default value for "low storage" is 10%. – shkschneider Jun 18 '15 at 15:50

1 Answers1

12

Per some related sample code from google you can take this route:

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

In other words, there is a DeviceStorageMonitorService service that runs at the OS level and detects a low storage situation. From there, it sends a sticky broadcast that any activity or service can check, later. In this example, they registered a null receiver as a way to just test if the sticky broadcast has been sent.

gMale
  • 17,147
  • 17
  • 91
  • 116