android - Get app sqlite database programmatically in file -


i want upload sqlite db file dropbox. before need sqlite db file in code. how can on device? checked on this link, , says user needs root permissions access database.

so in short:

how can access sqlite database non rooted devices? eg file f = new file("path_to_db_file");

if approach impossible, how can save app database in place able gain access it?

please let me know if can explain anything. thank in advance

yes can, worked me without root permission:

file db = new file("/data/data/your.package/databases/yourdatabasename");         date d = new date();           file file = new file("your_destination.db"); file.setwritable(true);  copyfile(new fileinputstream(db), new fileoutputstream(file)); 

copy file function this, , works in both directions db->file , file->db:

public static void copyfile(fileinputstream fromfile, fileoutputstream tofile) throws ioexception {     filechannel fromchannel = null;     filechannel tochannel = null;     try {         fromchannel = fromfile.getchannel();         tochannel = tofile.getchannel();         fromchannel.transferto(0, fromchannel.size(), tochannel);     } {         try {             if (fromchannel != null) {                 fromchannel.close();             }         } {             if (tochannel != null) {                 tochannel.close();             }         }     } } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -