 Thread Author
# 1

02-07-2012, 04:45 PM
|
| CrackBerry Abuser | | Join Date: Aug 2011 Posts: 325 Likes Received: 55
Thanked 18 Times in 15 Posts
| |
Android - PB Devs; assets not functioning?
Are assets not working for Android apps on PB?
I'm running the latest beta, but I wanna copy my database from the assets folder...not going too well.
I can create the database from scratch, but it's fairly large (if I do entries one by one, it'll take 60 seconds for a first-time load). Code: try {
InputStream myInput = this.getAssets().open(DATABASE_NAME);
String outFileName = DATABASE_PATH + DATABASE_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
Log.v("DB", "Is it copying?");
myOutput.flush();
myOutput.close();
myInput.close();
} catch (IOException e) {
Log.v("DB", e.getMessage());
} Error message is it cannot find the database file in /data/data/app.name/databases/file.db
I suppose it isn't creating the file like it would on Android devices. Code: dbStatus = SQLiteDatabase.openDatabase(DATABASE_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);
dbStatus.close(); Fixed - Sorry! I was too quick before posting :P. I had the idea of creating an empty database so that the file existed, then the copyDatabase() function would simply overwrite.
Last edited by TheStoof; 02-07-2012 at 04:48 PM.
|