private void exportTheDB() throws IOException
{
File myFile;
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
String TimeStampDB = sdf.format(cal.getTime());
try {
myFile = new File(extStorageDirectory+"/Export_"+TimeStampDB+".csv");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("Start time;End time;Elapse;Sports type");
myOutWriter.append("\n");
sampleDB = this.openOrCreateDatabase(DB_NAME,MODE_PRIVATE, null);
Cursor c = sampleDB.rawQuery("SELECT * FROM Sport_Records ", null);
if (c != null) {
if (c.moveToFirst()) {
do {
String start_Time = c.getString(c.getColumnIndex("startTimeDate"));
String end_Time = c.getString(c.getColumnIndex("endTimeDate"));
String elapse_Time = calculateTimeDifferece(end_Time, start_Time);
String sport_Name = c.getString(c.getColumnIndex("label"));
myOutWriter.append(start_Time+";"+end_Time+";"+elapse_Time+";"+sport_Name);
myOutWriter.append("\n");
}
while (c.moveToNext());
}
c.close();
myOutWriter.close();
fOut.close();
}
} catch (SQLiteException se)
{
Log.e(getClass().getSimpleName(),"Could not create or Open the database");
}
finally {
sampleDB.close();
}
}