PublicBitmap Getwebbitmap (String imgurl) {Bitmap Bitmap=NULL; Try{InputStream InputStream=NULL; URL url; URL=NewURL (Imgurl); if(URL! =NULL) { //Open ConnectionHttpURLConnection httpurlconnection =(httpurlconnection) URL. OpenConnection (); Httpurlconnection.setconnecttimeout (3000);//Set the network connection time-out to 3 secondsHttpurlconnection.setdoinput (true);//Open Input Stream intResponsecode = Httpurlconnection.getresponsecode ();//Get server response values if(Responsecode = = HTTPURLCONNECTION.HTTP_OK) {//Normal ConnectionInputStream = Httpurlconnection.getinputstream ();//Get input stream} bitmap=Bitmapfactory.decodestream (InputStream); } } Catch(Exception e) {e.printstacktrace (); } returnbitmap; }
It is best to get the bitmap to use it casually.
It should be noted that whenever you want to network: 1, you have to set access rights, 2, put in the thread to handle
<android:name= "Android.permission.INTERNET"/>
Android Gets the code of the picture on the page