zoukankan      html  css  js  c++  java
  • StorageReceiver

    package com.android.demo.lileidemo.listener;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Handler;

    import com.android.demo.lileidemo.MyApplication;
    import com.android.demo.lileidemo.constant.AppConstants;

    public class StorageReceiver extends BroadcastReceiver {
    private static final String TAG = AppConstants.APP_TAG + "StorageReceiver ";
    private static volatile StorageReceiver mInstance;
    private String ACTION_DEVICE_STORAGE_FULL = "android.intent.action.DEVICE_STORAGE_FULL";
    private String ACTION_DEVICE_STORAGE_NOT_FULL = "android.intent.action.DEVICE_STORAGE_NOT_FULL";
    //private static IIviStateChangeListener mIviStateChangeListener;//not static broadcast,set this to static
    private Handler mWorker;

    public StorageReceiver() {
    mWorker = new Handler();
    }

    /**
    * get Instance.
    *
    * @return instance.
    */
    public static StorageReceiver getInstance() {
    if (mInstance == null) {
    synchronized (StorageReceiver.class) {
    if (mInstance == null) {
    mInstance = new StorageReceiver();
    }
    }
    }
    return mInstance;
    }

    // public void registerIviStateChangeListener(
    // IIviStateChangeListener iviStateChangeListener) {
    // LogUtil.d(TAG + "registerIviStateChangeListener()");
    // mIviStateChangeListener = iviStateChangeListener;
    // }

    public void registerReceiver() {
    //LogUtil.d(TAG + "registerReceiver ");
    IntentFilter intentFilter = new IntentFilter();

    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    intentFilter.addAction(ACTION_DEVICE_STORAGE_FULL);
    intentFilter.addAction(ACTION_DEVICE_STORAGE_NOT_FULL);
    MyApplication.getAppContext().registerReceiver(StorageReceiver.getInstance(),
    intentFilter);
    }

    public void unregisterReceiver() {
    MyApplication.getAppContext().unregisterReceiver(StorageReceiver.getInstance());
    }

    @Override
    public void onReceive(Context context, Intent intent) {
    //LogUtil.d(TAG + "onReceive mIviStateChangeListener:" + mIviStateChangeListener);
    if (intent == null) {
    return;
    }
    String action = intent.getAction();
    //LogUtil.d(TAG + "onReceive action:" + action);

    }


    }
  • 相关阅读:
    python 换行符的识别问题,Unix 和Windows 中是不一样的
    MaxCompute小文件问题优化方案
    MaxCompute小文件问题优化方案
    C++ 中的sort()排序函数用法
    C++ 中的sort()排序函数用法
    简单记录几个有用的sql查询
    bzoj1084(SCOI2005)最大子矩阵
    bzoj1025(SCOI2009)游戏——唯一分解的思路与应用
    bzoj1087互不侵犯King(状压)
    bzoj2748(HAOI2018)音量调节
  • 原文地址:https://www.cnblogs.com/adamli/p/13140684.html
Copyright © 2011-2022 走看看