com.tencent.mm.sdk.modelmsg.WXImageObject Java Examples

The following examples show how to use com.tencent.mm.sdk.modelmsg.WXImageObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserInfoActivity.java    From WeGit with Apache License 2.0 6 votes vote down vote up
private void test() {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    WXImageObject imgObj = new WXImageObject(bmp);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;

    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 200, 200, true);
    bmp.recycle();
    msg.thumbData = BitmapUtils.bmpToByteArray(thumbBmp, true);  //

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = System.currentTimeMillis() + "";
    req.message = msg;
    req.scene = SendMessageToWX.Req.WXSceneSession;
    api.sendReq(req);
}
 
Example #2
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 6 votes vote down vote up
/***
 * @param path  the local image path
 */
public void shareImageByPath(String path,String title ,String desc,boolean shareToFriendCircle,IWXShareCallback callback){
    WXImageObject imgObj = new WXImageObject();
    imgObj.setImagePath(path);

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

   // Bitmap bmp = BitmapFactory.decodeFile(path);
    Bitmap bmp = new ImageParser(0,0).parseToBitmap(path);
    Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
    bmp.recycle();
    msg.thumbData = Util.bitampToByteArray(thumbBmp);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("img");
    req.message = msg;
    req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;

    mCallbackMap.put(req.transaction.hashCode(),callback);
    mWxApi.sendReq(req);
}
 
Example #3
Source File: WeixinHelper.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected SendMessageToWX.Req doInBackground(Object... params) {
    final String url = (String) params[0];
    final String title = (String)params[1];
    final String desc = (String)params[2];
    final boolean shareToFriendCircle = (Boolean)params[3];
    final IWXShareCallback callback = (IWXShareCallback)params[4];

    WXImageObject imgObj = new WXImageObject();
    imgObj.imageUrl = url;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    msg.title = title;
    msg.description = desc;

    final String transaction = buildTransaction("img");
    mCallbackMap.put(transaction.hashCode(), callback);
    try {
        Bitmap bmp = new ImageParser(0,0).parseToBitmap(IoUtil.getBytesFromStreamAndClose(
                new URL(url).openStream()));
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
        bmp.recycle();
        msg.thumbData =  Util.bitampToByteArray(thumbBmp);

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = transaction;
        req.message = msg;
        req.scene = shareToFriendCircle ? SendMessageToWX.Req.WXSceneTimeline
                : SendMessageToWX.Req.WXSceneSession;
        return req ;
    } catch (IOException e) {
        e.printStackTrace();
    }
    SendMessageToWX.Req req2 = new SendMessageToWX.Req();
    req2.transaction = transaction;
    req2.message = null;
    return req2;
}
 
Example #4
Source File: ShareActivity.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private boolean a(String s1, boolean flag)
{
    if (!t.isWXAppInstalled())
    {
        CustomToast.makeText(this, 0x7f0d017d, 0).show();
        return false;
    }
    WXImageObject wximageobject = new WXImageObject();
    wximageobject.setImagePath(s1);
    android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
    options.inSampleSize = 4;
    M = BitmapFactory.decodeFile(s1, options);
    WXMediaMessage wxmediamessage = new WXMediaMessage();
    wxmediamessage.mediaObject = wximageobject;
    wxmediamessage.title = v;
    wxmediamessage.description = w;
    if (M != null)
    {
        wxmediamessage.setThumbImage(M);
    }
    com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req req = new com.tencent.mm.sdk.modelmsg.SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = wxmediamessage;
    int i1 = 0;
    if (flag)
    {
        i1 = 1;
    }
    req.scene = i1;
    return t.sendReq(req);
}
 
Example #5
Source File: WxShareInstance.java    From ShareUtil with Apache License 2.0 4 votes vote down vote up
@Override
public void shareImage(final int platform, final ShareImageObject shareImageObject,
        final Activity activity, final ShareListener listener) {
    Observable.fromEmitter(new Action1<Emitter<Pair<Bitmap, byte[]>>>() {
        @Override
        public void call(Emitter<Pair<Bitmap, byte[]>> emitter) {
            try {
                String imagePath = ImageDecoder.decode(activity, shareImageObject);
                emitter.onNext(Pair.create(BitmapFactory.decodeFile(imagePath),
                        ImageDecoder.compress2Byte(imagePath, TARGET_SIZE, THUMB_SIZE)));
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    }, Emitter.BackpressureMode.BUFFER)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnRequest(new Action1<Long>() {
                @Override
                public void call(Long aLong) {
                    listener.shareRequest();
                }
            })
            .subscribe(new Action1<Pair<Bitmap, byte[]>>() {
                @Override
                public void call(Pair<Bitmap, byte[]> pair) {
                    WXImageObject imageObject = new WXImageObject(pair.first);

                    WXMediaMessage message = new WXMediaMessage();
                    message.mediaObject = imageObject;
                    message.thumbData = pair.second;

                    sendMessage(platform, message, buildTransaction("image"));
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    activity.finish();
                    listener.shareFailure(new Exception(throwable));
                }
            });
}
 
Example #6
Source File: ShareByWeixin.java    From ShareSDK with MIT License 4 votes vote down vote up
public void shareImg(Bitmap bitmap, OnShareListener listener) {
    if (null == bitmap) {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        return;
    }
    if (api.isWXAppInstalled()) {
        if (api.isWXAppSupportAPI()) {
            WXMediaMessage wxMediaMessage = new WXMediaMessage();
            wxMediaMessage.mediaObject = new WXImageObject(bitmap);

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            while (width * height > THUMB_SIZE * THUMB_SIZE) {
                width /= 2;
                height /= 2;
            }
            Bitmap thumbBmp = Bitmap.createScaledBitmap(bitmap, width, height, true);
            try {
                ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
                thumbBmp.compress(Bitmap.CompressFormat.JPEG, 85, localByteArrayOutputStream);
                wxMediaMessage.thumbData = localByteArrayOutputStream.toByteArray();
                localByteArrayOutputStream.close();
            } catch (Exception e) {

            }

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = String.valueOf(System.currentTimeMillis());
            req.message = wxMediaMessage;
            if (ShareConstant.SHARE_CHANNEL_WEIXIN_FRIEND == channel) {
                req.scene = SendMessageToWX.Req.WXSceneSession;
            } else if (ShareConstant.SHARE_CHANNEL_WEIXIN_CIRCLE == channel) {
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
            }
            api.sendReq(req);
        }
    } else {
        if (null != listener) {
            listener.onShare(channel, ShareConstant.SHARE_STATUS_FAILED);
        }
        ToastUtil.showToast(context, R.string.share_no_weixin_client, true);
    }
}