Jamendo 使用java.net.URL类访问网络数据

来源:互联网 发布:东西怎么在淘宝上拍卖 编辑:程序博客网 时间:2024/06/05 00:38

我们通过URL类或者HttpClient类,都可以对网络访问,至于这两个类的区别,HttpClient类底层还是使用了Url类,对其封装了一下。

 RemoteImageView类中:

..........

@Overrideprotected String doInBackground(String... params) {// TODO Auto-generated method stubmTaskUrl = params[0];InputStream stream = null;URL imageUrl;Bitmap bmp = null;try {imageUrl = new URL(mTaskUrl);try {stream = imageUrl.openStream();bmp = BitmapFactory.decodeStream(stream);try {if(bmp != null){JamendoApplication.getInstance().getImageCache().put(mTaskUrl, bmp);Log.d(JamendoApplication.TAG,"Image cached " + mTaskUrl);}else{Log.w(JamendoApplication.TAG, "failed to cache "+ mTaskUrl);}} catch (NullPointerException e) {// TODO Auto-generated catch blockLog.w(JamendoApplication.TAG, "failed to cache "+ mTaskUrl);}} catch (IOException e) {// TODO Auto-generated catch blockLog.w(TAG,"Could not load bitmap from url: " + mTaskUrl);}finally{try{if(stream != null)stream.close();}catch(IOException e){}}} catch (MalformedURLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return mTaskUrl;}


详细见:http://blog.csdn.net/a107494639/article/details/7331014

原创粉丝点击