2011-05-04 17 views

Respuesta

26

¿Es posible utilizar la clase gestor de descargas androide que he encontrado aquí

Sí, a pesar de que sólo está disponible desde el nivel de la API de Android 9 (versión 2.3). Here is a sample project demostrando el uso de DownloadManager.

+1

@ CommonsWare..I pasaron por su todo el código .all son grandes. Quiero hacer uso de DownloadManager con wifi significa ... Tengo que usar SFTP y descargar el archivo del enrutador ... ¿Es posible? me guiará por favor para esto .. – NovusMobile

+2

@Satyam: 'DownloadManager' no es compatible con SFTP. Nada en Android es compatible con SFTP AFAIK. Necesitará encontrar un JAR de terceros para eso. – CommonsWare

+0

Encontré esa API que utilicé en el nombre de Java "JSCH". @ CommonsWare En mi proyecto Java funciona perfectamente pero aquí Android no ... ¿es posible? o puedo enfrentar otro problema? pls reply .. – NovusMobile

6

clase Uso DownloadManager (pan de jengibre y más reciente solamente)

GingerBread trajo una nueva característica, DownloadManager, lo que le permite descargar archivos de forma fácil y delegar el trabajo duro de los hilos de manipulación, arroyos, etc., para el sistema.

En primer lugar, vamos a ver un método de utilidad: nombre

/** 
* @param context used to check the device version and DownloadManager information 
* @return true if the download manager is available 
*/ 
public static boolean isDownloadManagerAvailable(Context context) { 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { 
     return true; 
    } 
    return false; 
} 

del Método explica todo. Una vez que esté seguro de DownloadManager está disponible, se puede hacer algo como esto:

String url = "url you want to download"; 
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); 
request.setDescription("Some descrition"); 
request.setTitle("Some title"); 
// in order for this if to run, you must use the android 3.2 to compile your app 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
} 
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "name-of-the-file.ext"); 

// get download service and enqueue file 
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
manager.enqueue(request); 

Progreso de la descarga se muestra en la barra de notificaciones.

3
DownloadManager downloadmanager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
Uri uri = Uri.parse("http://www.example.com/myfile.mp3"); 
DownloadManager.Request request = new DownloadManager.Request(uri); 
request.setTitle("My File"); 
request.setDescription("Downloading"); 
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 
request.setDestinationUri(Uri.parse("file://" + folderName + "/myfile.mp3")); 
downloadmanager.enqueue(request); 
Cuestiones relacionadas