Is there any possible way to send SQLite db file of android app as email attachment..please guide me Android Developers
Asked
Active
Viewed 1,010 times
2 Answers
0
- Connect with your system, the rooted device or emulator with this app running on it.
- open command prompt and navigate to /sdk-directory/tools.
- type adb pull /data/data/com.example.app/databases/database.db where com.example.app is your application package name and database.db is the database file
You can attach this .db file to your email client, if it allows to.
Programatically you can do this using following code:
public void exportDatabse(String databaseName) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + getPackageName() + "//databases//" +databaseName+ "";
String backupDBPath = "backupname.db";
File currentDB = new File(data, 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();
}else{
System.out.println(":::");
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}

LoveForDroid
- 1,072
- 12
- 25
0
Yes this is possible. Kind of.
A possible way would be to iterate through every table you have and save the data as a string. This string can then be send as the content of an email with a share menu.
This has the advantage that you can "export" your database in every text based format you want, e.g. SQLite
, MySQL
, XML
, JSON
(actually someone already did a SQLite to JSON
method, click here)
Also you are in full control of the data you send. So you dont have to send everything if you don't need to
I hope I could help you out.