mercredi 15 avril 2015

Android: Import Export SQLite to web adress

I would like to export and import ma SQLite db to my web ardess http://ift.tt/1FToDFD This is my code for import/export to sd card. I've tried to make it work with HttpClient but no success. So i posted the code here if somenoe could edit it to import/export to that adress. I guess that the app will have to login to that adress? Thanks a lot!


This is the method that imports backup from sd;



private void importBaze() {
// TODO Auto-generated method stub
try {
String stanjeSd = Environment.getExternalStorageState();
if (stanjeSd.equals(Environment.MEDIA_MOUNTED)) {
File mkSdDir = Environment
.getExternalStoragePublicDirectory("/Crni03 Obracun");
mkSdDir.mkdirs();
} else {
Toast.makeText(BazaNovciPregled.this,
"Can't make bkp dir",
Toast.LENGTH_SHORT).show();
}
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "crni03.obracun"
+ "//databases//" + "BazaNovciDB";
String backupDBPath = "/Crni03 Obracun/troskovnik.db";
// From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(BazaNovciPregled.this, "Done",
Toast.LENGTH_SHORT).show();

}
} catch (Exception e) {
String error = e.toString();
d = new Dialog(this);
d.setTitle("Not done");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();

}
}


This is the method that imports backup from sd



private void exportBaze() {
// TODO Auto-generated method stub
try {
String stanjeSd = Environment.getExternalStorageState();
if (stanjeSd.equals(Environment.MEDIA_MOUNTED)) {
File mkSdDir = Environment
.getExternalStoragePublicDirectory("/Crni03 Obracun");
mkSdDir.mkdirs();
} else {
Toast.makeText(BazaNovciPregled.this,
"No sd card",
Toast.LENGTH_SHORT).show();
}
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "crni03.obracun"
+ "//databases//" + "BazaNovciDB";
String backupDBPath = "/Crni03 Obracun/troskovnik.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} catch (Exception e) {
String error = e.toString();
d = new Dialog(this);
d.setTitle("Not Done");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}
}

Aucun commentaire:

Enregistrer un commentaire