Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Check if the storage space is low on app boot

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?

like image 326
Jake Graham Arnold Avatar asked Jun 18 '15 15:06

Jake Graham Arnold


People also ask

Why is my storage full when I have no apps Android?

A cache can come in the form of hardware or software, and its function is to store data so that future requests for that data can be processed and provided in less time. But a cache can also harbor data that you no longer need, and therefore takes up storage space without you even realizing it.

Why is my Samsung storage always full?

It is normal to try out new Apps but how many Apps do you have sitting in your device, that are no longer in use? Just like temporary internet files stored in computer, Apps store temporary files in device's internal memory which can pile up eventually and take up a considerable amount of space.


1 Answers

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.

like image 83
gMale Avatar answered Oct 15 '22 17:10

gMale