下载Mp3文件(Android)

时间:2013-01-25 11:23:30

标签: java php android html browser

我让应用程序播放一些来自互联网的mp3文件 我想添加"下载按钮"从互联网上下载任何mp3文件 我想从浏览器下载,,,而不是从应用程序,,,但如果我想调用浏览器,如:


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


浏览器将播放此mp3文件:(

我想我可以在直接下载链接后添加东西,,,,任何人都可以帮帮我吗?

注意:如果您有从App上下载的代码,,请告诉我有关它的信息:) 我是android世界的新手:P和我想要一个简单的代码来理解它 谢谢大家:))

2 个答案:

答案 0 :(得分:5)

最好使用DownloadManager。 您可以通过Lars Vogel here

查看示例代码

相关位:

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

请注意,DownloadManager适用于API版本9(Android 2.3,Gingerbread)及更高版本。

答案 1 :(得分:0)

您可以将它放在download.php文件中

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

然后:

 Uri.parse("direct_download.php?file=filename.mp3");
相关问题