mjava获取网络图片
2023-01-24 09:16:15 最后更新
//Code By xiaoyi
说明:这样弄列表就不需要在列表里加浏览器来加载图片
mian.iyu
t()
{
  //参数:图片URL直链
  s picurl="http://img6.bdstatic.com/img/image/public/20180814.jpg"
  call(back,"mjava","Http.getInternetPicture",picurl)
  ufnsui()
  {
    //背景可以设置哦
    us(1,"background",back)
  }
}

Http.mjava

import android.app.*;
import android.content.*;
import android.graphics.*;
import android.net.*;
import java.io.*;
import java.net.*;
import android.graphics.drawable.*;

//获取网络图片
    public static BitmapDrawable getInternetPicture(String UrlPath) {  
        Bitmap bm = null;  
        String urlpath = UrlPath;  
        try {  
            URL uri = new URL(urlpath);  
            HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
            connection.setRequestMethod("GET");  
            connection.setReadTimeout(5000);  
            connection.setConnectTimeout(5000);  
            connection.connect();  
            if (connection.getResponseCode() == 200) {  
                InputStream is = connection.getInputStream();  
                bm = BitmapFactory.decodeStream(is);  
            } else {
                bm = null;  
            }  
        } catch (MalformedURLException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
        return new BitmapDrawable(bm);  

    }