从另一个应用程序访问项目资产? [英] Access Assests from another application?

查看:99
本文介绍了从另一个应用程序访问项目资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了很多的请求在我的应用程序,允许自定义图标从BetterCut /开回家包。它似乎工作的方式是安装BetterCut或打开主页,那么你就可以从市场安装吨,这些免费的图标包。一旦安装了这些应用程序(和其他应用程序)将轮询这些图标包和使用的图标。

I get a lot of requests in my application to allow for custom icons packs from BetterCut / Open Home. The way it seems to work is you install BetterCut or Open Home, then you can install tons of these free icon packs from the market. Once installed both those apps (and other apps) will poll for those icon packs and use the icons.

我想知道如何轮询资产的文件夹可用的安装应用程序。我已经打开了几个图标包,并确认有一个文件夹的资产在那里,他们是充满了图标的PNG文件。

I want to know how to poll the install applications for the asset folders that are available. I have opened up a few of the icon packs and verified that there is an assets folder in there and they are full of all the icon png files.

我已经搜查放在这里,等code部位,谷歌等,但没有带发现任何线索。

I've searched on here, other code sites, google, etc but havn't found any leads.

更新:

从下我已经写了一些code,试图从我自己的项目资产目录列表中的文件,但它似乎并没有工作。答案

From the answer below I have written some code to try and list a file from my own projects assets directory but it does not seem to work.

Resources r = this.getResources();
AssetManager a = r.getAssets();
String[] list = a.list("/");
Log.d("test", "Length of / is "+list.length);
for (String s : list) {
    Log.d("test", s);
}

Log.d("test", "Length of /assets is "+a.list("/assets").length);
Log.d("test", "Length of /assets/ is "+a.list("/assets/").length);
Log.d("test", "Length of /assets/ is "+a.list("/assets/").length);
Log.d("test", "Length of ./assets/ is "+a.list("./assets/").length);
Log.d("test", "Length of ./assets is "+a.list("./assets").length);

这是输出:

03-16 12:25:04.591: DEBUG/test(13526): Length of / is 6
03-16 12:25:04.591: DEBUG/test(13526): AndroidManifest.xml
03-16 12:25:04.591: DEBUG/test(13526): META-INF
03-16 12:25:04.591: DEBUG/test(13526): assets
03-16 12:25:04.591: DEBUG/test(13526): classes.dex
03-16 12:25:04.591: DEBUG/test(13526): res
03-16 12:25:04.591: DEBUG/test(13526): resources.arsc
03-16 12:25:04.614: DEBUG/test(13526): Length of /assets is 0
03-16 12:25:04.637: DEBUG/test(13526): Length of /assets/ is 0
03-16 12:25:04.661: DEBUG/test(13526): Length of /assets/ is 0
03-16 12:25:04.692: DEBUG/test(13526): Length of ./assets/ is 0
03-16 12:25:04.716: DEBUG/test(13526): Length of ./assets is 0

更新2 99%有!!!:

UPDATE 2 99% There!!!:

我想通了,你可以从资产目录中读取,而无需实际使用的文件夹名称:

I figured out that you can read from the assets directory without actually using the folder name:

InputStream is = assetManager.open("test.png");

我也试图与资产在机应用2从应用1,其中的文件夹路径/asset/icon/image.png:

I also tried this with an asset in Appliction 2 from Application 1, where the folder path is /asset/icon/image.png:

InputStream is = assetManager.open("icon/image.png");

接下来,我想通了,你可以列出的资产里面的目录:

Next I figured out that you can list a directory inside assets:

String[] list = assetManager.list("icons");

这也是伟大工程。唯一没有现在的问题是如何列出的基本目录的资产。

That also works great. The only thing failing right now is how to list the base directory assets.

推荐答案

要获取基本 /资产文件夹,你需要使用AssetsManager列出只有报价的目录

To get the base /assets folder you need to use the AssetsManager to list the directory with just quotes:

AssetManager am = this.getAssets();
String[] names = am.list("");

将有列出了一些其他文件:图像,声音,WebKit的,也许其他人。您可以忽略这些目录,它们是框架的资产目录中的一部分。这是从<一个报价href="http://groups.google.com/group/android-developers/browse_thread/thread/2b110c3c30d8df93/7d8191d6302bca2c"相对=nofollow> groups.google.com :

目前的资产管理公司合并的   从框架资产目录   随着自己的文件资源   摆在资产。我们应该   可能改变这种行为(这是   一个旧的资源/本地化的一部分   模型),但它并没有做太多的伤害   不同之处在于你会看到更多   在你自己的资产的文件/目录   比你想象的。您的任何   是相同的为一体,在文件   框架资产将被用来代替,   通过访问时的   AssetManager。

Currently the asset manager merges the asset directory from the framework resources along with your own files placed in "assets". We should probably change this behavior (it was part of an old resource/ localization model), but it doesn't do much damage except that you see more files/directories in your own assets than you might expect. Any of your files that are the same as one in the framework assets will be used instead, when accessed through your AssetManager.

您还可以列出资产目录中的子文件夹,不需要任何斜杠:

You can also list a subfolder inside the assets directory and do not need any slashes:

String[] names= am.list("subfolder");

请注意,我并​​没有包括/资产中的文件名。 最后,一​​旦你有你的文件的列表,你可以将它们在这样的:

Note that I did not include "/assets" in the filename. Finally once you have your list of files you can load them in like:

InputStream in = am.open("file.png");

这将加载在基础资产的文件夹中的文件。或者你可以在这样的子文件夹中加载文件:

That will load in a file in the base assets folder. Or you can load a file in a subfolder like this:

InputStream in = am.open("subfolder/file.png");

如果您需要加载这些PNG图像成位图,你也可以做到以下几点:

If you need to load those pngs into a Bitmap you can also do the following:

Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

这篇关于从另一个应用程序访问项目资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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