美文网首页
Android 微信图片分享

Android 微信图片分享

作者: 枫叶豆腐汤 | 来源:发表于2017-11-01 10:27 被阅读59次
     /**
         * 分享图片
         * @param imgurl 保存图片路径
         * @param sendtype 区分分享到朋友圈还是好友
         */
        public static void imageShare(String imgurl, int sendtype) {
            final IWXAPI api = WXAPIFactory.createWXAPI(App.getInstance(), Constant.WXID, true);
            File file = new File(imgurl);
            if (!file.exists()) {
                RxToast.error("图片不存在");
            }
            WXImageObject imgObj = new WXImageObject();
            imgObj.setImagePath(imgurl);
            WXMediaMessage msg = new WXMediaMessage();
            msg.mediaObject = imgObj;
            Bitmap bmp = BitmapFactory.decodeFile(imgurl);
            Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 100, 100, true);
            msg.setThumbImage(thumbBmp);
            bmp.recycle();
            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = String.valueOf(System.currentTimeMillis());
            req.message = msg;
            req.scene = sendtype == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
            api.sendReq(req);
        }
    

    相关文章

      网友评论

          本文标题:Android 微信图片分享

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