问题描述
我有两个单独的项目,加分和免费版。这两个项目都使用了大量的共享code,所以我试图被共享到一款Android库项目所有内容集成。
I have two separate projects, a plus and free version. Both projects use a considerable amount of shared code, so I am attempting to integrate everything that is shared into a Android Library Project.
一个共享资源的是,我已经坐在FreeProject /入资产价值/ database.db的数据库。这个文件是这两个项目之间共享,我想将它移动到LibraryProject /资产/ database.db。
One of the shared resources is a database that I had sitting in FreeProject/assests/database.db. This file is shared between both projects and I would like to move it to LibraryProject/assets/database.db.
在code,我的数据库移动到数据库文件夹具有以下内容:
In the code I was moving the database to the database folder with the following:
String dbLocation = "/data/data/" + myContext.getPackageName() + "/databases/" + DBNAME;
//Reading the asset and writing it to the database folder.
InputStream myInput = myContext.getAssets().open("database.db");
OutputStream myOutput = new FileOutputStream(dbLocation);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
所以我的问题是,我怎么能叫getAssets()来获取该库项目的AssetManager?还是有另一种方式,我可以/应该这样做呢?
So my question is, how can I call getAssets() to get an AssetManager for the library project? Or is there another way that I could/should be doing this?
推荐答案
从的:
该工具不支持使用原始的资源文件(保存在
资产/目录)在库项目。所使用的任何资源资产
一个应用程序必须存储在的资产/目录
应用项目本身。但是,资源文件保存在res /
目录的支持。
您能不能用RES /生 openRawResource()呢?
Could you use res/raw and openRawResource() instead?
这篇关于从Android的项目库检索资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!