如何下载Android应用程序的sqlite数据库? [英] how to download the sqlite database of an android app?
本文介绍了如何下载Android应用程序的sqlite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的 android 应用程序中使用 sqlite 数据库.我想把数据库下载到电脑上.谁能告诉我该怎么办?
I am using a sqlite database in my android app. I want to download the database to pc. Can anyone kindly tell me what to do ?
推荐答案
如果您的应用程序在模拟器中,您只需使用 DDMS 并打开 /data/data/your.package.name/databases
.
if your app is in emulator you can just use the DDMS and open /data/data/your.package.name/databases
.
如果您的应用在移动设备上.这是我将数据库复制到 sdcard root
文件夹的操作.
if you have your app in mobile. here is what i do to copy the db to the sdcard root
folder.
/** The name of the database file */
static final String DATABASE_NAME = "mydatabase.db";
static final String DATABASE_NAME_FULL = "/data/data/com.my.application/databases/" + DATABASE_NAME;
public static boolean backUpDataBase(Context context){
boolean result = true;
// Source path in the application database folder
String appDbPath = DATABASE_NAME_FULL;
// Destination Path to the sdcard app folder
String sdFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DATABASE_NAME;
InputStream myInput = null;
OutputStream myOutput = null;
try {
//Open your local db as the input stream
myInput = new FileInputStream(appDbPath);
//Open the empty db as the output stream
myOutput = new FileOutputStream(sdFolder);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
} catch (IOException e) {
result = false;
e.printStackTrace();
} finally {
try {
//Close the streams
if(myOutput!=null){
myOutput.flush();
myOutput.close();
}
if(myInput!=null){
myInput.close();
}
} catch (IOException e) { }
}
return result;
}
你需要在你的 manifest.xml 中使用这个
you need this in your manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
这篇关于如何下载Android应用程序的sqlite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文