![]() |
|
Programación y Desarrollo para Android Subforo exclusivo para temas de programación de software para PDAs y desarrollo de aplicaciones, interfaces, etc bajo Android |
«
Tema Anterior
|
Siguiente tema
»
|
Herramientas |
#1
|
Descargar Base de Datos - Sencillo
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/...a5thj/DB_v4.db El metodo se ejecuta cuando la BD no existe. Código:
@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);} -No me grafica el porcentaje de la descarga, ya probe de todo. ![]() -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? ![]() -Me consume muchisimos recursos (60 MB de ram) cuando se realiza la descarga. Gracias!! ![]() |
|
Respuesta |
![]() |
||||||
|
«
Tema Anterior
|
Siguiente tema
»
|
|
Hora actual: 13:31:09 (GMT +2)
HTCMania: líderes desde el 2007