android 6.0 SystemUI源码分析(6)-StorageNotification介绍
来源:互联网 发布:prim算法和迪杰斯特拉 编辑:程序博客网 时间:2024/06/04 18:51
StorageNotification继承于SystemUI,主要处理Storage事件,比如Storage插拔等。
在StorageNotfication的start函数,会去注册StorageEventListener。
@Override public void start() { mNotificationManager = mContext.getSystemService(NotificationManager.class); mStorageManager = mContext.getSystemService(StorageManager.class); mStorageManager.registerListener(mListener);对于U盘或SD卡插拔事件,我们常用的是通过广播的方式去接收,具体可以参考:
http://blog.csdn.net/zhudaozhuan/article/details/7199799
StorageEventListener的实现如下:
private final StorageEventListener mListener = new StorageEventListener() { @Override public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) { onVolumeStateChangedInternal(vol); } @Override public void onVolumeRecordChanged(VolumeRecord rec) { // Avoid kicking notifications when getting early metadata before // mounted. If already mounted, we're being kicked because of a // nickname or init'ed change. final VolumeInfo vol = mStorageManager.findVolumeByUuid(rec.getFsUuid()); if (vol != null && vol.isMountedReadable()) { onVolumeStateChangedInternal(vol); } } @Override public void onVolumeForgotten(String fsUuid) { // Stop annoying the user mNotificationManager.cancelAsUser(fsUuid, PRIVATE_ID, UserHandle.ALL); } @Override public void onDiskScanned(DiskInfo disk, int volumeCount) { onDiskScannedInternal(disk, volumeCount); } };StorageEventListener中还有其他的call back函数,对于外置存储设备插拔,我觉得这两个函数应该都可以拿到对应的事件:
public void onStorageStateChanged(String path, String oldState, String newState)
public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState)
在StorageNotification使用的是onVolumeStateChanged和onVolumeRecordChanged
private void onVolumeStateChangedInternal(VolumeInfo vol) { switch (vol.getType()) { case VolumeInfo.TYPE_PRIVATE: onPrivateVolumeStateChangedInternal(vol); break; case VolumeInfo.TYPE_PUBLIC: onPublicVolumeStateChangedInternal(vol); break; } }TYPE_PRIVATE和TYPE_PUBLIC没有详细的解释,对于U盘TYPE_PUBLIC。
private void onPublicVolumeStateChangedInternal(VolumeInfo vol) { Log.d(TAG, "Notifying about public volume: " + vol.toString()); final Notification notif; switch (vol.getState()) { case VolumeInfo.STATE_UNMOUNTED: notif = onVolumeUnmounted(vol); break; case VolumeInfo.STATE_CHECKING: notif = onVolumeChecking(vol); break; case VolumeInfo.STATE_MOUNTED: case VolumeInfo.STATE_MOUNTED_READ_ONLY: notif = onVolumeMounted(vol); showMMDialog(); break; case VolumeInfo.STATE_FORMATTING: notif = onVolumeFormatting(vol); break; case VolumeInfo.STATE_EJECTING: notif = onVolumeEjecting(vol); break; case VolumeInfo.STATE_UNMOUNTABLE: notif = onVolumeUnmountable(vol); break; case VolumeInfo.STATE_REMOVED: notif = onVolumeRemoved(vol); break; case VolumeInfo.STATE_BAD_REMOVAL: notif = onVolumeBadRemoval(vol); break; default: notif = null; break; }VolumeInfo记录了外置存储设备的状态,根据不同的状态,进行相应的处理。
0 0
- android 6.0 SystemUI源码分析(6)-StorageNotification介绍
- android 6.0 SystemUI源码分析(1)-SystemUI介绍
- android 6.0 SystemUI源码分析(1)-SystemUI介绍
- android 6.0 SystemUI源码分析(1)-SystemUI介绍 转
- android 6.0 SystemUI源码分析(1)-SystemUI介绍
- android 6.0 SystemUI源码分析(5)-PowerUI介绍
- android 6.0 SystemUI源码分析(2)-SystemUI启动流程
- android 6.0 SystemUI源码分析(2)-SystemUI启动流程
- systemui开发---PowerUI && StorageNotification
- Android SystemUI源码分析(一)
- android 6.0 SystemUI源码分析(4)-StatusBar显示流程
- android 6.0 SystemUI源码分析(4)-StatusBar显示流程
- 基于Android源码的SystemUI分析
- Android SystemUI源码分析与修改
- Android SystemUI源码分析与修改
- SystemUI源码分析
- SystemUI源码分析
- Android学习 ——SystemUIService之StorageNotification分析
- django-pagination---七步教你实现Django网站列表自动分页
- [LeetCode]101. Symmetric Tree
- Python中os.path的妙用
- 如何部署Python Web应用:记录一次Heroku部署完整过程
- Python+Apache+CGI完全配置
- android 6.0 SystemUI源码分析(6)-StorageNotification介绍
- Django分页的基本实现办法
- 在CentOS上源码安装MySQL+安装问题解决+安全优化
- 在CentOS上使用yum安装MySQL+安全优化
- 在CentOS上部署开源博客系统Blog_mini
- 在Ubuntu上使用apt-get安装MySQL+安全优化
- 在Ubuntu上部署开源博客系统Blog_mini
- 在Ubuntu上源码安装MySQL+安装问题解决+安全优化
- Blog_mini完整部署文档