安卓assetManager [英] android assetManager

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

问题描述

我需要得到绝对路径的资产到文件夹。 一些像这样的SD卡:

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

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

我做不正确的?

What i do incorrect?

首先,我试图让路(绿色ractangle)这种方式,但我alwase得到假。 然后我评论此块并试图让getAssets()路径表()。 但我得到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:

看的图片

帮助我获得绝对路径,我的文件文件夹。

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()。表(文件)。 (您必须使用子目录, 因为这个)。

  • 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(文件名)获得的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.

修改

我不知道你所说的大规模的意思,但如果要加载的文件 black.png 的资产,而不是SD卡,然后写这样的:

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
};

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

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