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 had low internal memory. So, I downloaded a few extra apps (my phone has a very small internal memory) which caused the OS to display the notification that the system memory is low. The phone had 10 - 15 MB remaining. However, my broadcast receiver never received that intent. Yet, the system notification stays in the notification bar, and I am not able to browse the internet because of low internal memory.
Should this intent be broadcasted whenever the low internal memory notification is displayed? Or is there some even lower threshold of memory that will send out this broadcast that I haven't hit yet on my phone? In the documentation it only says "Broadcast Action: A sticky broadcast that indicates low memory condition on the device." Since it doesn't actually define "low memory condition," I don't know if I am doing something wrong, or if I simply haven't hit that condition yet.
Here is the code for my BroadcastReceiver:
public class MemoryBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
Log.isExternalStorageProblem = false;
Log.clearNotification(Log.externalMemoryNotificationID);
}
if (action.equals(Intent.ACTION_DEVICE_STORAGE_OK)) {
Log.isInternalStorageLow = false;
Log.clearNotification(Log.internalMemoryNotificationID);
}
if (action.equals(Intent.ACTION_DEVICE_STORAGE_LOW)) {
Log.isInternalStorageLow = true;
Log.displayMemoryNotification("Internal Storage Low",
"The internal storage is low, Please fix this.",
"Please clear cache and/or uninstall apps.", Log.internalMemoryNotificationID);
}
}
}
I have a service that initializes the receiver, adds the intent filter and registers it (among other things):
private MemoryBroadcastReceiver memoryBroadcastReciever = new MemoryBroadcastReceiver();
public void registerBroadcastReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
filter.addDataScheme("file");
this.getApplicationContext().registerReceiver(memoryBroadcastReciever, filter);
}
@Override
public void onCreate() {
registerBroadcastReceiver();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…