I do not know how exactly your database structure is, but since you can already read this data, my suggestion goes from this point on.
First, you need the write permission, which you should include in your Manifest
file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And so, here is an example method that receives a list of Pessoa
and saves the name and phone information. This is where you will replace and use the way you read this data from your bank:
private void salvarArquivoPessoas(List<Pessoa> lista) {
String filename = "pessoas.txt";
StringBuffer sb = new StringBuffer();
for (Pessoa pessoa : lista) {
sb.append(pessoa.getNome() + ";" + pessoa.getTelefone() + "\n");
}
String strToSave = sb.toString();
FileOutputStream outputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(strToSave.getBytes());
outputStream.close();
} catch (Exception e) {
Log.e("SAVE_FILE", e.getMessage());
}
}
This method you need to run on a different thread, so it's recommended to use within a % with_% / a>.
With this, you will get the AsyncTask
file, which with it you use according to your need, either to send by email share or simply read next. More details, you can see here .