Can we 开发者_StackOverflowpush a database that is created by some ide like sqlitestudio and push it into our emulator for app uses? is there any way to push our ".db" format into andriod emulator?
I think you want to ship you application by creating database outside , these are good tutorial to add database to your application , and these are few good tutorials to start with
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
http://mfarhan133.wordpress.com/2010/10/24/database-crud-tutorial-for-android/
http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/
If your device is an emulator or is a physical device connected thru USB, you can use this command-line:
adb push c:\local_path\myfile.db /path_on_the_device/myfile
You better add db into assets and copy it into sd or internal storage. Here is some code snippet for you
private void CopyFileFromAssets() {
AssetManager asm = getAssets();
String[] files = null;
try {
files = asm.list("");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
try {
in = asm.open(filename);
//you can even create folder to put your file
out = new FileOutputStream("/sdcard/" + filename);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
Hope this can help
Go to file explorer - data - data - your pkg name - select database and click on push a file onto the device.
First remove the db extension.
1.then select DDMS
2.then select emulator from device tab
3.move to data/data//databases
4.now push file into emulator using the top-right open in window.
5.Now run the app.
Thank you.
精彩评论