下载意图
Download Intent
我一直在开发一个电影应用程序,用户可以通过直接下载电影 link。
最后我有问题。
android 是否有下载意图?
我希望当用户单击一个按钮时,会显示一个对话框,用户可以选择其中一个下载器(下载应用程序),他们想要吗!
就像我们在浏览器中直接点击一个link。
你可以试试下面这个
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);
这会显示一个浏览器列表,您可以从中选择一个并开始下载。
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();
我一直在开发一个电影应用程序,用户可以通过直接下载电影 link。 最后我有问题。 android 是否有下载意图? 我希望当用户单击一个按钮时,会显示一个对话框,用户可以选择其中一个下载器(下载应用程序),他们想要吗! 就像我们在浏览器中直接点击一个link。
你可以试试下面这个
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);
这会显示一个浏览器列表,您可以从中选择一个并开始下载。
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();