public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
private Context ctx;
public ExportDatabaseFileTask(Context ctx) {
super();
this.ctx=ctx;
}
protected Boolean doInBackground(final String... args) {
File dbFile =
new File(Environment.getDataDirectory() + "/data/[com.your.pkg]/databases/[pkg]");
File exportDir = new File(Environment.getExternalStorageDirectory(), "");
if (!exportDir.exists()) {
exportDir.mkdirs();
}
File file = new File(exportDir, dbFile.getName());
try {
file.createNewFile();
this.copyFile(dbFile, file);
return true;
} catch (IOException e) {
Log.e("birthdroid", e.getMessage(), e);
return false;
}
}
protected void onPostExecute(final Boolean success) {
if (success) {
Toast.makeText(ctx, "Export successful!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ctx, "Export failed", Toast.LENGTH_SHORT).show();
}
}
void copyFile(File src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
}
输出SQLite database 到sd卡
原创mb649166f4c151e 博主文章分类:android ©著作权
文章标签 SQLite Boo 文章分类 JavaScript 前端开发
上一篇:webView显示progress indicator
下一篇:sms信息的获得
-
APP数据存储到SD卡 android 应用数据存到sd卡
【Android】Android 移动应用数据到SD 在应用的menifest文件中指定就可以了,在 <manifest> 元素中包含android:installLocation 属性,设置其值为"internalOnly"即可,如下:<manifest xmlns:android="http://schemas.android.com/apk/
APP数据存储到SD卡 android Android SD AndroidManifest Storage