放在哪里的资产文件是一个应用程序访问? [英] Where to put an asset file to be accessible for an application?

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

问题描述

得到了一些最近的更新,即从Eclipse的转移到Android Studio和使用摇篮开始。此外,我的目标API得到16升级到20,事情不工作,因为他们习惯了。

Got some updates recently, i.e. moved from Eclipse to Android Studio and started using Gradle. Besides, my target API got updated from 16 to 20 and things are not working as they used to.

我开始重构负责获取数据库文件我的应用程序的一部分。但是LogCat中报告没有资产应用程序/应用程序/资产目录(资产是在同一级别为的src DIR),虽然我的 dbfile.sqlite 是存在的。

I started refactoring a part of my application responsible for fetching a database file. But LogCat reports no assets in application/app/assets directory, (assets is at the same level as src dir), although my dbfile.sqlite is there.

当我检查,我有资产之间以下的事情:

As I checked, I have the following things among assets:

AssetManager assetManager = getAssets();
String[] assetFile = assetManager.list("");

for (int i = 0; i < assetFile.length; i++) {
Log.d(PTAG, "Assets found [" + i + "]: " + assetFile[i]);
}

输出:

D/MainActivity﹕ Assets found [0]: images
D/MainActivity﹕ Assets found [1]: sounds
D/MainActivity﹕ Assets found [2]: webkit

一无所知的数据库。你知道在哪里可以把我的数据库文件,以及如何提供应用程序呢?

Nothing about databases. Do you know where to put my database file and how to provide the application with it?

推荐答案

好吧,女士们,先生们。我得到了答案。

Okay, Ladies and Gentlemen. I got the answer.

如果你让你的应用程序向后兼容和 com.android.support 导入库,检查子目录,该文件夹中:你可能有应用程序兼容性-V7 和/或支持-V4 。而在这些目录中你会还可以找到资产文件夹: assetManager.list()从我的例子是指他们。

If you make your application backwards compatible and import libraries from com.android.support, check subdirectories in that folder: you'll probably have appcompat-v7 and/or support-v4. And in those directories you'll find also assets folders: assetManager.list() from my example refers to them.

长话短说:如果你计划在API 4和/或API 7使用predefined资产,确保你的资产将被复制到各子目录下的 com.android.support

Long story short: if you plan to use predefined assets in API 4 and/or API 7, make sure your assets are copied to respective subdirectories beneath com.android.support.

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

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