My app was working fine until the latest Android update and then everything broke. You have already helped me repair the issues I had reading and writing CSV files with OpenCSV.
However, the database still does not work.
I’m assuming that the problem is very similar.
This copies the db file in from an external source…
public boolean copyFileIn(Context context)
{
try
{
File sd = new File(Environment.getExternalStorageDirectory() + "/Android/data/com.gmail.alan.j.haden.bestmobile/files");
File data = new File(Environment.getDataDirectory() + "/user/0/com.gmail.alan.j.haden.bestmobile");
SQLiteDatabase db = this.getReadableDatabase();
String dbPath = db.getPath();
if (sd.canWrite())
{
String currentDBPath = "/data/com.gmail.alan.j.haden.bestmobile/databases/ProductData.db";
String backupDBPath = "/BEST/ProductDB/ProductData.db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(backupDB).getChannel();
FileChannel dst = new FileOutputStream(currentDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
System.out.println("Import successful");
return true;
} else {
System.out.println("Can't find currentDBPath");
}
}
}
catch (Exception e) {
Log.w("Settings Backup", e);
}
return false;
}
and this exports it…
public boolean copyFileOut(Context context)
{
try
{
File sd = context.getExternalFilesDir(null);
File data = context.getDataDir();
SQLiteDatabase db = this.getReadableDatabase();
String dbPath = db.getPath();
if (sd.canWrite())
{
String currentDBPath = "/data/com.gmail.alan.j.haden.bestmobile/databases/ProductData.db";
System.out.println("dbPath = " + dbPath);
String backupDBPath = "/BEST/ProductDB/ProductData.db";
File currentDB = new File(data, currentDBPath);
System.out.println("currentDBPath = " + currentDBPath);
File backupDB = new File(sd, backupDBPath);
if (currentDB.exists()) {
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
System.out.println("Export successful");
return true;
} else {
System.out.println("Can't find currentDBPath");
}
}
}
catch (Exception e) {
Log.w("Settings Backup", e);
}
return false;
}
After I’ve got this part working again, I’ll be able to see if the database can still be read.