두 개의 별도 프로젝트 인 +와 + 무료 버전이 있습니다. 두 프로젝트 모두 상당한 양의 공유 코드를 사용하므로 공유되는 모든 것을 Android 라이브러리 프로젝트에 통합하려고합니다.Android Lib Project에서 자산 가져 오기
공유 리소스 중 하나는 내가 FreeProject/assests/database.db에 앉아 있었던 데이터베이스입니다. 이 파일은 두 프로젝트에서 공유되며이를 LibraryProject/assets/database.db로 옮기고 싶습니다.
이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를 얻을 수있다 : 나는 다음과 같이 데이터베이스 폴더로 데이터베이스를 이동 한 코드에서
? 아니면 제가 할 수있는 또 다른 방법이 있습니까? docs에서
덕분에 다음 새 코드를 사용하여 작동시킬 수있었습니다. 'Configuration c = new Configuration(); c.setToDefaults(); InputStream myInput = 새 리소스 (myContext.getAssets(), null, c) .openRawResource (R.raw.database); OutputStream myOutput = 새 FileOutputStream (dbLocation); –