安卓资产管理器 [英] android assetManager

查看:39
本文介绍了安卓资产管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取资产中文件夹的绝对路径.有些人喜欢这样的 SD 卡:

I need to get Absolute path to Folder in Assets. Some like this for sd-card:

final String sdDir = Environment.getExternalStorageDirectory() + "Files";

我做错了什么?

首先,我尝试以这种方式获得路径(在绿色 ractangle 中),但我总是得到错误".然后我评论这个块并尝试从 getAssets().list(); 获取路径但是我第一次看到的是 3 个文件夹.

First I try to get path (in green ractangle) this way but I alwase get "False". Then I comment this block and try to get path from getAssets().list(); But I get 3 folders witch I see first time.

我想像这样绿色"一样大,但我需要使用资产中的文件:

I want to make massive like this "green" but I need to use files from assets:

看图片

帮助我获取我的 Files 文件夹的绝对路径.

Help me to get absolute path to my Files folder.

推荐答案

我不太确定你要做什么,所以我会尝试覆盖基础,也许这会有所帮助.

I'm not exactly sure what you're trying to do, so I'll try to cover the bases, and maybe this will help.

  • 如果您只是想获取资产中的内容列表,那么使用 getAssets().list("Files").(你必须使用子目录,因为这个).

  • If you are just trying to get a list of what's in your assets, then use getAssets().list("Files"). (You have to use the subdirectory, because of this).

如果您尝试获取资产目录的绝对路径(或任何子目录),你不能.资产目录中的任何内容在 APK 中.它不像 SD 卡那样位于外部存储设备中.

If you are trying to get an absolute path to your assets directory (or any subdirectory), you can't. Whatever is in the assets directory is in the APK. It's not in external storage like on an SD card.

如果您尝试打开资产目录中的文件,请使用AssetManager.open(filename) 获取InputStream.这里,文件名应该是资产目录的相对路径.

If you are trying to open up files in the assets directory, use AssetManager.open(filename) to get the InputStream. Here, filename should be the relative path from the assets directory.

编辑

我不确定你所说的大量"是什么意思,但如果你想从资产而不是 SD 卡加载文件 black.png,那么写这个:

I'm not sure what you mean by "massive", but if you want to load the file black.png from assets instead of the SD card, then write this:

// must be called from Activity method, such as onCreate()
AssetManager assetMgr = this.getAssets();
mColors = new Bitmap[] {
    BitmapFactory.decodeStream(assetMgr.open("black.png"));
    // and the rest
};

这篇关于安卓资产管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆