zoukankan      html  css  js  c++  java
  • Android 微信网址分享添加网络图片

    public static void share(String CustomEventData,String title,String titlle_detail,String imgUrl)throwsMalformedURLException{
    
            Log.e(TAG,"share##########################");
    
            Log.e(TAG,imgUrl);
    
            WXWebpageObject webpage=newWXWebpageObject();
    
            webpage.webpageUrl="https://fir.im/5et2";
    
            WXMediaMessage msg=newWXMediaMessage(webpage);
    
            msg.title=title;
    
            msg.description=titlle_detail;
    
    
    //加载本地图片
    
    //        Bitmap thumb = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.zhuye_tip);
    
    //        msg.setThumbImage(thumb);
    
    //        thumb.recycle();
    
    
    //加载网络图片********
    
    //注意下方的压缩
    
            try{
    
            Bitmap thumb=BitmapFactory.decodeStream(new URL(imgUrl).openStream());
    
    //注意下面的这句压缩,120,150是长宽。
    
    //一定要压缩,不然会分享失败
    
            Bitmap thumbBmp=Bitmap.createScaledBitmap(thumb,120,150,true);
    
    //Bitmap回收
    
            thumb.recycle();
    
            msg.thumbData=Util.bmpToByteArray(thumbBmp,true);
    
    //            msg.setThumbImage(thumb);
    
            }catch(IOException e){
    
            e.printStackTrace();
    
            }
    
            Log.e(TAG,msg.title);
    
            Log.e(TAG,msg.description);
    
    //构造Req
    
            SendMessageToWX.Req req=newSendMessageToWX.Req();
    
            req.transaction=buildTransaction("webpage");
    
            req.message=msg;
    
            Log.e(TAG,CustomEventData);
    
            if(Integer.parseInt(CustomEventData)==0){
    
            req.scene=SendMessageToWX.Req.WXSceneSession;
    
            }
    
            else{
    
            req.scene=SendMessageToWX.Req.WXSceneTimeline;
    
            }
    
            api.sendReq(req);//发送到微信
    
            Log.e(TAG,"share###### END ####################");
    
            }
  • 相关阅读:
    寒假作业:第三次作业
    markdown笔记
    c#基类继承
    atom插件安装
    git命令
    vue2.3时使用手机调试,提示媒体已断开的解决方案
    vue中使用hotcss--stylus
    JS调试工具
    Facebook的bigpipe
    xss--攻击方式
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/7872277.html
Copyright © 2011-2022 走看看