1

Buen dia, descargo un archivo con downloadManager pero quisiera descargar cualquier archivo sin importar la extensión ya que por el momento en esta linea

Download_Uri = Uri.parse("https://server/Itemoftheday.pdf"); 

debo indicar la extensión del archivo, esta es la parte del downloadManager:

downloadManager = (DownloadManager)    getSystemService(Context.DOWNLOAD_SERVICE);
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Download_Uri = Uri.parse("https://server/Itemoftheday.pdf");

btndownload.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    {
        list.clear();

        DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setAllowedOverRoaming(false);
        request.setTitle("App" + "Itemoftheday" + ".pdf");
        request.setDescription("Downloading " + "Itemoftheday" + ".pdf");
        request.setVisibleInDownloadsUi(true);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/Score/"  + "/" + "itemoftheday" + ".pdf");


        refid = downloadManager.enqueue(request);

        Log.e("OUT", "" + refid);
        list.add(refid);

De antemano gracias.

1 respuesta 1

1

Simplemente define una variable que contenga el nombre del archivo en donde se defina el nombre y su extensión, ejemplo:

String fileName =  "Itemoftheday.txt";

ahora definela en tu código:

downloadManager = (DownloadManager)    getSystemService(Context.DOWNLOAD_SERVICE);
registerReceiver(onComplete,
new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Download_Uri = Uri.parse("https://server/" + fileName );

btndownload.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    {

        list.clear();

        DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
        request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
        request.setAllowedOverRoaming(false);
        request.setTitle("App" + fileName );
        request.setDescription("Downloading " + fileName );
        request.setVisibleInDownloadsUi(true);
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/Score/"  + "/" + fileName );

        refid = downloadManager.enqueue(request);
        Log.e("OUT", "" + refid);
        list.add(refid);
1
  • gracias por tu apoyo, fijate que hice lo que has dicho pero aun sigue descargando extensión .pdf únicamente, yo quisiera que descargue .mp3, .bmp, y demás
    – Sergio
    el 8 may. 2019 a las 1:17

Tu Respuesta

Al pulsar en “Publica tu respuesta”, muestras tu consentimiento a nuestros términos de servicio, política de privacidad y política de cookies

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.