JoseBoretto
04/08/14, 22:37:38
Hola a todos, tengo una aplicacion simple que DESCARGA UNA BASE DE DATOS en:
/data/data/com.jose.pakage/databases/DBexterna3.db
La descarga se realiza desde la siguiente url:
https://dl.dropboxusercontent.com/s/nk3i8sn8iea5thj/DB_v4.db
El metodo se ejecuta cuando la BD no existe.
@Override
protected Boolean doInBackground(Void... params) {
try {
// Log.d(TAG, "downloading database");
URL url = new URL(dwnload_file_path);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
int lenghtOfFile = ucon.getContentLength();
long total=0;
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(100000);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
//Grafica el porcentaje de descarga
total += current;
publishProgress((int)total/lenghtOfFile); //Esto no ANDA
}
/* Convert the Bytes read to a String. */
File dest_file = new File(dest_file_path);
FileOutputStream fos = null;
fos = new FileOutputStream(dest_file);
// Select storage location
//fos = context.openFileOutput("db_name.s3db", Context.MODE_PRIVATE);
fos.write(baf.toByteArray());
fos.close();
fos.flush();
baf.clear();
bis.close();
pDialog.dismiss();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
//Actualizo el valor del progreso de Dialog
@Override
protected void onProgressUpdate(Integer... values) {
int progreso = values[0].
pDialog.setProgress(progreso);}
Tengo 3 problemas:
-No me grafica el porcentaje de la descarga, ya probe de todo.:loco:
-Cuando termina la descarga, hago la consulta, me da error xq no existe y la vuelve a descargar.
Recien ahi funciona.. Porque se descarga 2 veces?:oh:
-Me consume muchisimos recursos (60 MB de ram) cuando se realiza la descarga.
Gracias!! :dios:
/data/data/com.jose.pakage/databases/DBexterna3.db
La descarga se realiza desde la siguiente url:
https://dl.dropboxusercontent.com/s/nk3i8sn8iea5thj/DB_v4.db
El metodo se ejecuta cuando la BD no existe.
@Override
protected Boolean doInBackground(Void... params) {
try {
// Log.d(TAG, "downloading database");
URL url = new URL(dwnload_file_path);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
int lenghtOfFile = ucon.getContentLength();
long total=0;
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(100000);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
//Grafica el porcentaje de descarga
total += current;
publishProgress((int)total/lenghtOfFile); //Esto no ANDA
}
/* Convert the Bytes read to a String. */
File dest_file = new File(dest_file_path);
FileOutputStream fos = null;
fos = new FileOutputStream(dest_file);
// Select storage location
//fos = context.openFileOutput("db_name.s3db", Context.MODE_PRIVATE);
fos.write(baf.toByteArray());
fos.close();
fos.flush();
baf.clear();
bis.close();
pDialog.dismiss();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
//Actualizo el valor del progreso de Dialog
@Override
protected void onProgressUpdate(Integer... values) {
int progreso = values[0].
pDialog.setProgress(progreso);}
Tengo 3 problemas:
-No me grafica el porcentaje de la descarga, ya probe de todo.:loco:
-Cuando termina la descarga, hago la consulta, me da error xq no existe y la vuelve a descargar.
Recien ahi funciona.. Porque se descarga 2 veces?:oh:
-Me consume muchisimos recursos (60 MB de ram) cuando se realiza la descarga.
Gracias!! :dios: