在我的应用程序中,我已经注册了一个广播接收器来接收系统意图ACTION_DEVICE_STORAGE_LOW.每当手机的内部记忆力都很低时,我都期待这样播出.所以,我下载了一些额外的应用程序(我的手机有一个非常小的内部存储器),导致操作系统显示系统内存不足的通知.电话剩余10 – 15 MB.但是,我的广播接收者从来没有收到这个意图.然而,系统通知停留在通知栏中,由于内部内存不足,我无法浏览互联网.
每当显示低内部存储器通知时,是否应广播这个意图?还是有一些甚至更低的内存阈值,会发出这个广播,我还没有打到我的手机?在文档中,它只说“广播操作:指示设备内存条件低的粘性广播”.既然它没有实际定义“低内存条件”,我不知道我做错了什么,或者我根本没有达到这个条件.
以下是我的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);
}
}
}
我有一个初始化接收器的服务,添加意图过滤器并注册它(除其他外):
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();
}