Skip to content

Instantly share code, notes, and snippets.

@Xhendor
Created May 26, 2015 19:38
Show Gist options
  • Save Xhendor/d0ac9d7527bcaaadd7c9 to your computer and use it in GitHub Desktop.
Save Xhendor/d0ac9d7527bcaaadd7c9 to your computer and use it in GitHub Desktop.
Extraer base de datos
Button botonExtraer = (Button) findViewById(R.id.boton_extraer);
botonExtraer.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmmss").format(new Date());
final String inFileName = "/data/data/com.app.mx.registro/databases/registro";
File dbFile = new File(inFileName);
FileInputStream fis = null;
try {
fis = new FileInputStream(dbFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String directorio = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+"/BASE_DE_DATOS_APP_REGISTRO/";
Log.e("ruta:", "" + directorio);
File d = new File(directorio);
if (!d.exists()) {
d.mkdir();
}
String outFileName = directorio + "registro_"+timeStamp+".sqlite";
OutputStream output = null;
try {
output = new FileOutputStream(outFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] buffer = new byte[1024];
int length;
try {
while ((length = fis.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
output.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
Intent enviarArchivo = new Intent();
File outFile=new File(outFileName);
enviarArchivo.setAction(Intent.ACTION_SEND);
enviarArchivo.setType("text/plain");
enviarArchivo.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outFile));
startActivity(enviarArchivo);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment