The URL (Uniform Resource Locator) object represents the Uniform Resource Locator, which is a pointer to the Internet "resource".
To read a network resource using a URL:
ImportJava.io.InputStream;ImportJava.net.URL;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;Importandroid.graphics.BitmapFactory;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivity {ImageView show; Bitmap Bitmap; Handler Handler=NewHandler () { Public voidhandlemessage (android.os.Message msg) {if(Msg.what = = 0x123) {System.out.println ("Handlermsg"); Show.setimagebitmap (bitmap); } } }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Show=(ImageView) Findviewbyid (r.id.show); NewThread () { Public voidrun () {Try { //System.out.println (url.tostring ());SYSTEM.OUT.PRINTLN (666); //The URL should be the download link to the image;URL url =NewURL ("http://dl.image.so.com/d?imgurl=http%3A%2F%2Fimg.tupianzj.com%2Fuploads%2Fallimg%2F160522% 2f9-160522114s1.jpg&purl=http%3a%2f%2fwww.tupianzj.com%2fgaoxiao%2fbiaoqing%2f20160522%2f50570_7.html& key=72e4826817 "); System.out.println (Url.tostring ()); InputStream is=Url.openstream (); Bitmap=Bitmapfactory.decodestream (IS); Handler.sendemptymessage (0x123); Is.close (); } Catch(Exception e) {e.printstacktrace (); } }; }.start (); }}
A URL is used to access the image resource and is displayed, where the URL should be the download link address for the corresponding picture resource.
Use URLs to read network resources in Android