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 ####################");

        }

 

posted @ 2017-11-21 11:18  星辰之力  阅读(1298)  评论(0编辑  收藏  举报