2016-12-11 23 views
0

我一直在开发一个电影应用程序,用户可以通过直接链接下载电影。 在结束部分我有问题。 Android是否有意下载? 我想,当用户点击一个按钮,一个对话框显示,用户可以选择下载(下载应用程序)之一,他们想要! 就像我们点击浏览器中的一个直接链接一样。下载意向

+0

看到这个问题:https://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog?rq=1 – Xander

+0

@Xander我看到它 这个问题是关于创建一个自定义的下载管理器。 我想要一个意图选择下载器下载。 –

回答

1

你可以试试这个下面

Uri uri = Uri.parse("http://apache.claz.org/nifi/1.1.0/nifi-1.1.0-bin.tar.gz"); 
Intent it = new Intent(Intent.ACTION_VIEW,uri); 
startActivity(it); 

这也显示了浏览器的列表,你可以选择从他们的下载将开始。

+0

我试过了。这种方式适用于下载二进制文件,就像.zip或.tar 但在我的情况下是电影格式,如.mkv或.mp4 –

+0

_Download_或_play_取决于您的Web服务器配置,如果您添加'add_header内容类型应用程序/八位字节流; '到你的nginx服务器配置,然后浏览器将下载,但不能播放它。试试这个网址'Uri uri = Uri.parse(“http://test.issll.com/demo/videoviewdemo.mp4”); ' –

0
new Thread(new Runnable() 
{ 
    public void run() 
    { 
     File outputFile=new File("//sdcard//downloadCase.mp3"); 
     try 
     { 
      if(!outputFile.exists()) 
     { 
      outputFile.createNewFile(); 
     } 
     else 
     { 
      outputFile.delete(); 
      outputFile.createNewFile(); 
     } 
     //CHANGE URL HERE 
     URL u = new URL("http://dl.blugaa.com/lq.blugaa.com/cdn7/3c0883064579a332dd7b627e3a904284/ylzuv/Mere%20Kol-(Mr-Jatt.com).mp3"); 
     URLConnection conn = u.openConnection(); 
     int contentLength = conn.getContentLength(); 

     DataInputStream stream = new DataInputStream(u.openStream()); 

     byte[] buffer = new byte[contentLength]; 
     stream.readFully(buffer); 
     stream.close(); 

     DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile)); 
     fos.write(buffer); 
     fos.flush(); 
     fos.close(); 
     } 
     catch(FileNotFoundException e) 
     { 
      return; // swallow a 404 
     } 
     catch (IOException e) 
     { 
      return; // swallow a 404 
     } 

    } 
}).start();