android – 广播ACTION_DEVICE_STORAGE_LOW的意图是什么时候?

在我的应用程序中,我已经注册一个广播接收器来接收系统意图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();

  }

解决方法

TL; DR

只要设备制造商不更改认设置,当可用内存达到内部设备内存的10%时,意图将被广播.

长版

我通过这个意图的Android源代码,我得到了一个名为DeviceStorageMonitorService的类

(位于:frameworks / base / services / java / com / android / server / DeviceStorageMonitorService.java)

从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.

所以你有它.只要设备制造商没有改变,它将在10%.

检查源代码,DeviceStorageMonitor发出一个粘性广播:(第354行)

mContext.sendStickybroadcast(mStorageLowIntent);

这意味着即使在广播完成后,您可以通过注册接收者来捕获数据.

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).

希望这可以帮助.

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...