AssetManager
AssetManager用于获取assets下的资源。
1、getassets()得到AssetManager
2、AssetManager.close() 关闭AssetManager
3、Resources和Assets 中的文件只可以读取而不能进行写的操作。
4、AssetManager类常用方法:
返回指定路径下的所有文件及目录名:
final String[] list(String path)
使用 ACCESS_STREAMING模式打开assets下的指定文件:
final InputStream open(String fileName)
使用显示的访问模式打开assets下的指定文件:
final InputStream open(String fileName, int accessMode)
访问assets下的资源:
1、访问assets下的网页:
//实例化WebView对象
webview = new WebView(this);
//加载需网页
webview.loadUrl("file:///android_asset/index.html");
setContentView(webview);
注意:文件名字不能带有空格和其他非法字符,只能英文字母大小、数字、下划线。
2、访问图片和文本文件
AssetManager asset=getAssets();
InputStream in=null;
try {
in=asset.open("images/logo.gif");
Bitmap bitmap=BitmapFactory.decodeStream(in);
imageview1.setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} try {
in=asset.open("test/test.txt"); ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int byteCount=0;
while((byteCount=in.read(buffer))!=-1){
outSteam.write(buffer,0,byteCount);
}
byte[] buffer1=outSteam.toByteArray();
String str=new String(buffer1);
Log.i("Test", str); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
3、获取assets的文件及目录名:
// path为文件夹路径
String fileNames[] =context.getAssets().list(path);
AssetManager的更多相关文章
- Android ndk下用AssetManager读取assets的资源
转自:http://www.cppblog.com/johndragon/archive/2012/12/28/196754.html 在使用 cocos2dx 在 Android 上进行游戏开发时, ...
- AssetManager asset的使用
Android 系统为每个新设计的程序提供了/assets目录,这个目录保存的文件可以打包在程序里./res 和/assets的不同点是,android不为/assets下的文件生成ID.如果使用/a ...
- 简单改造 starling 中的 AssetManager 让其更适合 批次加载纹理
API文档参考:http://doc.starling-framework.org/core/starling/utils/AssetManager.html 项目想以不改动starling的情况下对 ...
- AssetManager中的路径参数不能包含"assets/"
String path = “music/bg.mp3”: //正确的参数 //String path = “assets/music/bg.mp3”: //错误的参数 //String path = ...
- AssetManager asset使用
Android 该系统提供了一个程序为每个新的设计/assets文件夹.保存该文件在此文件夹可以在一个程序被打包./res 和/assets所不同的是,android不/assets下生成的文件ID. ...
- libgdx学习记录16——资源加载器AssetManager
AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...
- assets raw 资源 AssetManager
assets raw 目录简介 assets核心特性:不会被编译成二进制,支持子目录(可以分类,这是相对raw目录最大的好处),通过文件名访问,调用getAssets通过AssetManager访问 ...
- NDK,在JNI层使用AssetManager读取文件
NDK,二进制文件数据读取,在JNI层,通过AAssetManager读取asset内部的资源: 需要头文件的支持 #include <android/asset_manager_jni.h&g ...
- Android之AssetManager使用
1. 获取AssetManager AssetManager assetManager = context.getAssets(); 2. 列出assets文件夹下全部文件 String[] file ...
随机推荐
- shell脚本使用--sleep
#!/bin/bash #filename.sh echo -n Count: tput sc count=; while true; do ]; then let count++; ; tput r ...
- yii去掉自动排序功能
Yii去掉自动排序功能并自定义排序 public function search($params) { $query = SvnManage::find()->addOrderBy([ 'cre ...
- Java 多线程 创建线程的4种方式
1 继承Thread类,重写run方法.Thread类实现了Runnable接口. 2 实现Runnable接口,重写run方法.相比于继承Thread类,可以避免单继承的缺陷和实现资源共享. 举例: ...
- spring接入swagger后单元测试报错
2017-05-16 11:58:05.276 INFO 11268 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing ...
- Disruptor 详解
想了解一个项目,最好的办法就是,把它的源码搞到本地自己捣鼓. 在网上看了 N 多人对 Disruptor 速度的吹捧,M 多人对它的机制分析,就连 Disruptor 官方文档中,也 NB 哄哄自诩: ...
- Gson 2.8.jar基础
1.下载包 json { xxx:xxx,xx:xxx,...... } 对象符号 都可以下载 Gson 开源项目 Jackson 杰克逊 Fastjson ...
- let's encrypt申请
let's encrypt申请 https://keelii.com/2016/06/12/free-https-cert-lets-encrypt-apply-install/ https://ww ...
- bimgotoblock-BIM要上区块链
比特币(BitCoin)的暴涨暴跌让参与者体验着过山车的感觉,有人一夜暴富.别墅靠海,也有人拍断大腿或者恨不得跳楼了此残生.世人也更多的听说了比特币底层的依托--区块链(BlockChain) 技术. ...
- 【T11】提防对等实体的不友好动作
1.好的软件应该能够处理各种可能的错误,也就是防御式编程. 2.作为服务端,应该检测客户端的终止,客户端的无效输入.
- InfluxDB源码阅读之snapshotter服务
操作系统 : CentOS7.3.1611_x64 go语言版本:1.8.3 linux/amd64 InfluxDB版本:1.1.0 服务模块介绍 源码路径: github.com/influxda ...