Download gif from given URL

只愿长相守 提交于 2019-12-13 02:33:55

问题


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");
        }

回答1:


You cannot run networking operations on the main thread. Use AsyncTask for that.



来源:https://stackoverflow.com/questions/28454719/download-gif-from-given-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!