美文网首页iApp
iApp-v3 调用java加载网络图片

iApp-v3 调用java加载网络图片

作者: 明日未期 | 来源:发表于2019-08-12 23:50 被阅读0次

    新建webpic.mjava
    代码:

    import android.graphics.drawable.BitmapDrawable;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.InputStream;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    
        public static BitmapDrawable get(String url){
            BitmapDrawable pic = null;
            try{
                URL u = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) u.openConnection();
                conn.setRequestMethod("GET");
                conn.setConnectTimeout(5000);
                conn.setReadTimeout(5000);
                InputStream is = conn.getInputStream();
                Bitmap bmp = BitmapFactory.decodeStream(is);
                pic = new BitmapDrawable(bmp);
                is.close();
                conn.disconnect();
            }catch(Exception e){}
            return pic;
        }
    

    iyu调用
    代码:

    t(){
      s id=图像id
      s img_url=xxx
      call(img,"mjava","webpic.get",img_url)
      ufnsui(){
        us(id, "src", img)
      }
    }
    

    相关文章

      网友评论

        本文标题:iApp-v3 调用java加载网络图片

        本文链接:https://www.haomeiwen.com/subject/dlrmjctx.html