Android开发中,获取Assets资源要从AssetManager中获取,而AssetManager可以从Resource中进行获取。而Resource可以获取Id、drawablw、string、menu等资源。
Assets目录下的文件是不经过压缩的。
AssetManager assetManager = getResources().getAssets();
try {
InputStream inputStream = assetManager.open("file");
} catch (IOException e) {
e.printStackTrace();
}
扩展:
1、插件化如何实现加载资源呢?
AssetManager中有个addAssetPath方法,将APK路径传入改路径。改方法是hide的、使用反射即可。
/**
* @deprecated Use {@link #setApkAssets(ApkAssets[], boolean)}
* @hide
*/
@Deprecated
public int addAssetPath(String path) {
return addAssetPathInternal(path, false /*overlay*/, false /*appAsLib*/);
}