首页 > 微信 > 详细

Android 微信网址分享添加网络图片

时间:2017-11-21 11:24:46      阅读:436      评论:0      收藏:0      [点我收藏+]
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 ####################");

        }

 

Android 微信网址分享添加网络图片

原文:http://www.cnblogs.com/zhujiabin/p/7872277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!