Android 微信图片分享

 /**
     * 分享图片
     * @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 微信图片分享)