从给定的URL下载Gif [英] Download gif from given URL
本文介绍了从给定的URL下载Gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从给定的URL下载GIF,但有一个问题。我困在这里,不知道要下载此文件的正确方法。如何修复呢?我有样本网址: http://i1.kwejk.pl/k/ obrazki / 2015/02 / 6f0239004a643dbd9510ebda5a6f22b3.gif
我的code:
{尝试
的System.out.println(this.adressToGif);
网址URL =新的URL(urltoGif);
康涅狄格州的URLConnection = url.openConnection();
//conn.connect();
InputStream为= conn.getInputStream(); //它崩溃这里,并跳转到赶上()
二BufferedInputStream为=新的BufferedInputStream(是);
bis.mark(conn.getContentLength());
bis.close(); gifPlayer =新NewGifPlayer(这一点,之二); //电影电影= Movie.de codeStream(之二);
}赶上(例外X)
{
的System.out.println(有问题);
}
解决方案
您不能运行在主线程联网操作。使用的AsyncTask
为
I'm trying to download GIF from given Url but there is a problem. I'm stuck here and don't know the correct way to download this file. How to repair this? I have sample url: http://i1.kwejk.pl/k/obrazki/2015/02/6f0239004a643dbd9510ebda5a6f22b3.gif
My code:
try{
System.out.println(this.adressToGif);
URL url = new URL(urltoGif);
URLConnection conn = url.openConnection();
//conn.connect();
InputStream is = conn.getInputStream(); //IT crashes here and jumps to catch()
BufferedInputStream bis = new BufferedInputStream(is);
bis.mark(conn.getContentLength());
bis.close();
gifPlayer = new NewGifPlayer(this, bis);
//Movie movie = Movie.decodeStream(bis);
}catch(Exception x)
{
System.out.println("There is a problem");
}
解决方案
You cannot run networking operations on the main thread. Use AsyncTask
for that.
这篇关于从给定的URL下载Gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文