简体   繁体   中英

Download Mp3 Files (Android)

I have Application play some mp3 files from the internet and I want to add "Download Button" to download any mp3 file from the internet I want to download from the browser ,,, not from Application ,,, but if I want to call the browser such as :


startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("xxxx.xxxx.xxxx.mp3")));


the browser going to play this mp3 file :(

I think I can add thing after the link to download directly ,,,, any one can help me ?

Note : if you have a code to download from the App ,,, tell me about it also :) I'm new in android world :P and I want a simple code to can understand it thank you all :)

You would be better off using the DownloadManager . You can see example code by Lars Vogel here

The relevant bit:

DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        Request request = new Request(
                Uri.parse("http://www.vogella.de/img/lars/LarsVogelArticle7.png"));
        enqueue = dm.enqueue(request);

Note that DownloadManager is available on API version 9 (Android 2.3, Gingerbread) and upwards.

You can put this in your download.php file

 <?php
     $file = $_GET['file'];
     header ("Content-type: octet/stream");
     header ("Content-disposition: attachment; filename=".$file.";");
     header("Content-Length: ".filesize($file));
     readfile($file);
     exit;
   ?>

and then:

 Uri.parse("direct_download.php?file=filename.mp3");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM