本文介绍了当意图ACTION_DEVICE_STORAG​​E_LOW广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我已经注册的广播接收器接收系统的意图ACTION_DEVICE_STORAG​​E_LOW。我原以为这是广播每当手机具有低内存。所以,我下载了一些额外的应用程序(我的手机有一个非常小的内存),这引起了操作系统,以显示该系统内存不足的通知。这款手机有10 - 15 MB的剩余。然而,我的广播接收器从来没有收到这一意图。然而,系统通知停留在通知栏,我无法浏览的,因为低内存互联网。

如果这种意图可以随时显示在低内存的通知广播?还是有一些内存甚至更低的阈值,将发出这个广播,我都打不还我的电话?在本文档中只说广播事件:一个持久广播,表示设备上的内存不足因为它实际上并没有界定内存不足的情况​​,我不知道如果我做错了什么,或者我根本没有打的情况呢。

下面是code我BroadcastReceiver的:

 公共类MemoryBroadcastReceiver扩展的BroadcastReceiver {

公共无效的onReceive(上下文的背景下,意图意图){

    串动= intent.getAction();

    如果(action.equals(Intent.ACTION_MEDIA_MOUNTED)){
        Log.isExternalStorageProblem = FALSE;
        Log.clearNotification(Log.externalMemoryNotificationID);
    }

    如果(action.equals(Intent.ACTION_DEVICE_STORAG​​E_OK)){
        Log.isInternalStorageLow = FALSE;
        Log.clearNotification(Log.internalMemoryNotificationID);
    }

    如果(action.equals(Intent.ACTION_DEVICE_STORAG​​E_LOW)){
        Log.isInternalStorageLow = TRUE;
        Log.displayMemoryNotification(内部存储低,
                内部存储容量很小,请解决这个问题。
                请清除高速缓存和/或卸载应用程序。,Log.internalMemoryNotificationID);
    }
}
}
 

我有一个初始化接收服务,增加了意图过滤器,并将其注册(除其他事项外):

 私人MemoryBroadcastReceiver memoryBroadcastReciever =新MemoryBroadcastReceiver();

公共无效registerBroadcastReceiver(){
    IntentFilter的过滤器=新的IntentFilter();
    filter.addAction(Intent.ACTION_DEVICE_STORAG​​E_OK);
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_DEVICE_STORAG​​E_LOW);
    filter.addDataScheme(文件);

    。this.getApplicationContext()registerReceiver(memoryBroadcastReciever,过滤器);
}

@覆盖
公共无效的onCreate(){
    registerBroadcastReceiver();

  }
 

解决方案

TL; DR

只要设备制造商不会更改默认设置,其目的将在可用内存达到内部设备内存的10%播出。

龙版

我grepped通过Android源$ C ​​$下的意图,我得到了一类名为 DeviceStorageMonitorService

(位于:框架/基/服务/爪哇/ COM /安卓/服务器/ DeviceStorageMonitorService.java 的)

从javadoc的:

所以你有它。只要设备制造商并没有改变的是,它会在10%以上。

签出源$ C ​​$ ca的有点多了,DeviceStorageMonitor散发出持久广播:(354线)

  mContext.sendStickyBroadcast(mStorageLowIntent);
 

这意味着广播结束,即使你可以通过注册上的意图接收器捕捉到的数据。

从Android开发者 - 上下文:

希望这会有所帮助。

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();

  }
解决方案

TL;DR

As long as the device maker doesn't change the default settings, the intent will be broadcast when the free memory reaches 10% of the internal device memory.

Long Version

I grepped through the Android source code for that intent and I got to a class called DeviceStorageMonitorService

(located at: frameworks/base/services/java/com/android/server/DeviceStorageMonitorService.java)

From the javadoc:

So there you have it. As long as the device maker doesn't change that, it will be at 10%.

Checking out the source code a bit more, the DeviceStorageMonitor sends out a sticky Broadcast: (line 354)

mContext.sendStickyBroadcast(mStorageLowIntent);

Which means that even after the broadcast is finished you can catch the data by registering a receiver on that intent.

from Android Developer - Context :

hope this helps.

这篇关于当意图ACTION_DEVICE_STORAG​​E_LOW广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 00:54