0

I am trying to let users import and export their sqlite database from the data/data directory through various means e.g. email, onedrive, google drive, internal and external storage etc. I am not quite sure how to do this. I have the following code at the moment which saves it to their SD card. I am not sure how to move from here.

public static void export() throws IOException {
    //Open your local db as the input stream
    String inFileName = "/data/data/com.example.main/databases/myDB";
    File dbFile = new File(inFileName);
    FileInputStream fis = new FileInputStream(dbFile);

    String outFileName = Environment.getExternalStorageDirectory()+"/myDB";
    //Open the empty db as the output stream
    OutputStream output = new FileOutputStream(outFileName);
    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = fis.read(buffer))>0){
        output.write(buffer, 0, length);
    }
    //Close the streams
    output.flush();
    output.close();
    fis.close();
}

Could someone please help me out and show me how to export the SQLite database using email, onedrive etc. whatable capable medium the user has on their device.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Andrew
  • 1
  • 1
  • A better idea would be to make the database a networked one. – Phantômaxx Feb 12 '17 at 10:38
  • Sorry, I am fairly new to android, what is a networked database? – Andrew Feb 12 '17 at 14:02
  • A database which resides on a server and you can query it from wherever you are in the world. It has nothing to do with Android in particular. It's a pretty common concept. – Phantômaxx Feb 12 '17 at 14:03
  • Also without being offensive, I fail to see how this question is a *exact* duplicate of the proposed post. – Andrew Feb 12 '17 at 14:04
  • You said you wanted to share a binary file (a database is a binary file, do you agree on this?). Read carefully how it's done, in the linked duplicate. – Phantômaxx Feb 12 '17 at 14:06

0 Answers0