I have tried implementing the following code. I am using my emulator and it has sdcard storage space. I have inserted A.db using adb commands and I can see that the database is the specified path.
public void importDB() {
String dir=Environment.getExternalStorageDirectory().getAbsolutePath();
File sd = new File(dir);
File data = Environment.getDataDirectory();
FileChannel source = null;
FileChannel destination = null;
String backupDBPath = "/data/com.example.mine.move/databases/A.db";
String currentDBPath = "A.db";
File currentDB = new File(sd, currentDBPath);
File backupDB = new File(data, backupDBPath);
try {
source = new FileInputStream(currentDB).getChannel();
Toast.makeText(this,source.toString(),Toast.LENGTH_SHORT).show();
destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(this, "Please wait", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
But I keep getting the following error message:
java.io.FileNotFoundException: /storage/emulated/0/A.db: open failed: EACCES (Permission denied)
I have used the following permissions as well.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />