Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Populate database in android 4.4 using phonegap?

OP Delliany

10th July 2014, 03:06 AM   |  #1  
OP Junior Member
Thanks Meter: 0
1 posts
Join Date:Joined: Jul 2014
I can't populate database in android 4.4 using phonegap when I run my app the first time, but if I close the app and open it again this task works fine.

I have a 0000000000000001.db in assets and I want put this in Android 4.4 memory.

How can I deal with such Issue?

I'm using this code to populate the database in Android 4.4 memory

public void copyDatabase(){ 

// DB_NAME2 = "Databases.db"; 
//ASSETS = "0000000000000001.db"; 
//DB_PATH2 = "/data/data/com.example.testapp/app_webview/databases/"; 
//DB_PATH3 = "/data/data/com.example.testapp/app_webview/databases/file__0/"; 
//DB_NAME3 = "1"; 

String path = DB_PATH2 + DB_NAME2; 
String path2 = DB_PATH3 + DB_NAME3; 
File checkDatabase = new File(DB_PATH2); 
File checkDatabase2 = new File(DB_PATH3); 

if (!checkDatabase.exists()) 
if (!checkDatabase2.exists()) 

InputStream is = context.getAssets().open(DB_NAME2); 
OutputStream os = new FileOutputStream(path); 
InputStream is2 = context.getAssets().open(ASSETS); 
OutputStream os2 = new FileOutputStream(path2); 

byte[] buffer = new byte[10240]; 
int line; 

while ((line = is.read(buffer))>0) 
os.write(buffer, 0, line); 


buffer = new byte[10240]; 
line = 0; 

while ((line = is2.read(buffer))>0) 
os2.write(buffer, 0, line); 

}catch(IOException e){ 
System.out.println("Problem "+e); 
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes