안드로이드 프로젝트 폴더중에 assets이 있습니다.
이곳에 DB 파일을 넣고
이것을 /data/data/패키지명/databases에 복사하셔서 쓰시면 됩니다.
이러면 SD카드 관련 퍼미션을 얻지 않아도 쉽게 DB파일을 배포할 수 있습니다.
public static final String PACKAGE_DIR = "/data/data/패키지명/";
public static final String DATABASE_NAME = "upgrade.db";
public static final String COPY2DATABASE_NAME = "upgradebuf.db";
public static final int DB_VERSION = 1;
public static void initialize(Context ctx) {
// check
File folder = new File(PACKAGE_DIR + "databases");
folder.mkdirs();
File outfile = new File(PACKAGE_DIR + "databases/" + COPY2DATABASE_NAME);
if (outfile.length() <= 0) {
Log.i("db","buffer make");
AssetManager assetManager = ctx.getResources().getAssets();
try {
InputStream is = assetManager.open(DATABASE_NAME, AssetManager.ACCESS_BUFFER);
long filesize = is.available();
byte [] tempdata = new byte[(int)filesize];
is.read(tempdata);
is.close();
outfile.createNewFile();
FileOutputStream fo = new FileOutputStream(outfile);
fo.write(tempdata);
Log.d("db init", "success + size = "+outfile.length());
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
else{
//Log.i("db","buffer already exist, nothing to do");
}
}