[Android Pro] StorageManager简介
StorageManager
StorageManager is the interface to the systems storage service. The storage manager handles storage-related items such as Opaque Binary Blobs (OBBs).
OBBs contain a filesystem that maybe be encrypted on disk and mounted on-demand from an application. OBBs are a good way of providing large amounts of binary assets without packaging them into APKs as they may be multiple gigabytes in size. However, due to their size, they're most likely stored in a shared storage pool accessible from all programs. The system does not guarantee the security of the OBB file itself: if any program modifies the OBB, there is no guarantee that a read from that OBB will produce the expected output.
Get an instance of this class by calling getSystemService(java.lang.String) with an argument of STORAGE_SERVICE.
从Android 2.3开始新增了一个OBB文件系统和StorageManager类用来管理外部存储上的数据安全。
如果我们设计一款资源包含比较多的游戏,可能你会发现最终生成的APK文件可能高达300MB,但是APK文件很大导致Android系统无法正常安装,而这么大其实都是游戏中用到的资源文件,我们放到SD卡上可能其他应用也可以访问,比如说系统的图片管理器会索引游戏中的图片资源,而音乐播放器也会索引资源中的音乐,所以Android 2.3的OBB文件(Opaque Binary Blob)可以很好的解决大文件在SD卡上分离出APK文件,同时别的程序没有权限访问这样一种隔离的文件系统。
android.os.storage.StorageManager类的实例化方法需要使用 getSystemService(Contxt.STORAGE_SERVICE)才可以,eoe再次提醒这是一个API Level至少为9才能调用的类,注意SDK版本以及目标设备的固件。
我们知道android上一般都有外置的存储卡,
但是通过Environment.getExternalStorageDirectory()获取的是内置的存储卡位置 (也有的手机可以在系统中修改默认存储) 那么如何获取外置存储卡的位置呢?
通过StorageManager来获取多个sdcard,比使用cat /proc/mounts要好:
public static String[] getStoragePaths(Context cxt) {
List<String> pathsList = new ArrayList<String>();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.GINGERBREAD) {
StringBuilder sb = new StringBuilder();
try {
pathsList.addAll(new SdCardFetcher().getStoragePaths(new FileReader("/proc/mounts"), sb));
} catch (FileNotFoundException e) {
e.printStackTrace();
File externalFolder = Environment.getExternalStorageDirectory();
if (externalFolder != null) {
pathsList.add(externalFolder.getAbsolutePath());
}
}
} else {
StorageManager storageManager = (StorageManager) cxt.getSystemService(Context.STORAGE_SERVICE);
try {
Method method = StorageManager.class.getDeclaredMethod("getVolumePaths");
method.setAccessible(true);
Object result = method.invoke(storageManager);
if (result != null && result instanceof String[]) {
String[] pathes = (String[]) result;
StatFs statFs;
for (String path : pathes) {
if (!TextUtils.isEmpty(path) && new File(path).exists()) {
statFs = new StatFs(path);
if (statFs.getBlockCount() * statFs.getBlockSize() != 0) {
pathsList.add(path);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
File externalFolder = Environment.getExternalStorageDirectory();
if (externalFolder != null) {
pathsList.add(externalFolder.getAbsolutePath());
}
}
}
return pathsList.toArray(new String[pathsList.size()]);
}
[Android Pro] StorageManager简介的更多相关文章
- Android资源文件简介
Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, 资源 ...
- Android Action Bar简介
Android Action Bar简介 Design: Action Bar Action Bar是在屏幕顶端的一部分内容,通常在整个app进行中都保持存在. 它提供了几个关键的功能: 1.使得重要 ...
- eclipse安装androidSDK地址,Android SDK Manager简介
eclipse安装android插件地址:https://dl-ssl.google.com/android/eclipse 这个和安装其他插件方式一样:Help—Install New Softwa ...
- 【Android 系统开发】 Android 系统启动流程简介
作者 : 万境绝尘 (octopus_truth@163.com) 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/3889548 ...
- android.net.Uri 简介 API
android.net.Uri 简介 public abstract class android.net.Uri extends Object implements Parcelable, Compa ...
- IDA Pro基本简介
IDA Pro基本简介 IDA加载完程序后,3个立即可见的窗口分别为IDA-View,Named,和消息输出窗口(output Window). IDA图形视图会有执行流,Yes箭头默认为绿色,No箭 ...
- Android Notification通知简介
Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...
- Android MediaPlayer 基础简介
本文链接: Android MediaPlayer 基础简介 简单介绍MediaPlayer的基本概念,状态,常用的方法与监听器. 什么是MediaPlayer MediaPlayer类可以用来播放音 ...
- [Android Pro] Android下toolbox简介
toolbox是Android 自带的提供shell命令的软件.有点类似于busybox,但功能上好像弱很多.其源码可以从Android source code 中system/core/toolbo ...
随机推荐
- mui 怎样监听scroll事件的滚动距离
var scroll = mui('.mui-scroll-wrapper').scroll(); document.querySelector('.mui-scroll-wrapper' ).add ...
- linux命令(48):nl命令
nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...
- linux命令(29):cd命令
例1:进入系统根目录 cd / cd ../.. // [直接退到当前根目录] 例2:使用 cd 命令进入当前用户主目录 cd 例3:跳转到指定目录 cd /home/test 例4:返回进入此目 ...
- ZOJ-3430
Detect the Virus Time Limit: 2 Seconds Memory Limit: 65536 KB One day, Nobita found that his c ...
- maven新建web项目提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
maven新建web项目提示The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu ...
- selenium+python自动化78-autoit参数化与批量上传【转载】
转至博客:上海-悠悠 前言前一篇autoit实现文件上传打包成.exe可执行文件后,每次只能传固定的那个图片,我们实际测试时候希望传不同的图片.这样每次调用的时候,在命令行里面加一个文件路径的参数就行 ...
- 深度学习方法:受限玻尔兹曼机RBM(二)网络模型
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术.应用感兴趣的同学加入 上解上一篇RBM(一)基本概念, ...
- 按书上的例子,写了个长的go代码
用于实现快速排序和冒泡排序的东东. 包括了蛮多东西的实现,输入输出,字符串处理等.... bubblesort.go package bubblesort func BubbleSort(values ...
- 六十四 asyncio
asyncio是Python 3.4版本引入的标准库,直接内置了对异步IO的支持. asyncio的编程模型就是一个消息循环.我们从asyncio模块中直接获取一个EventLoop的引用,然后把需要 ...
- C/C++ 基础知识
C/C++ 基础知识 C 语言优秀学习网站 [C Programming Language] C 语言的注释 单行注释 /* comment goes here */ // comment goes ...