当前位置: 首页>>代码示例>>Java>>正文


Java WXMediaMessage类代码示例

本文整理汇总了Java中com.tencent.mm.sdk.modelmsg.WXMediaMessage的典型用法代码示例。如果您正苦于以下问题:Java WXMediaMessage类的具体用法?Java WXMediaMessage怎么用?Java WXMediaMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WXMediaMessage类属于com.tencent.mm.sdk.modelmsg包,在下文中一共展示了WXMediaMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shareToWeChat

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareToWeChat(final Context context, final String appId, final String title, final String desc,
                                 final String url, final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            msg.description = desc;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneSession;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
开发者ID:yangjie127,项目名称:ESSocialSDK-master,代码行数:27,代码来源:WeChatShareProxy.java

示例2: shareToWeChatTimeline

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareToWeChatTimeline(final Context context, final String appId, final String title, final String url,
                                         final String thumbnail, final IWXShareCallback callback) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            WeChatShareProxy.mCallback = callback;
            WXWebpageObject webpage = new WXWebpageObject();
            webpage.webpageUrl = url;
            WXMediaMessage msg = new WXMediaMessage(webpage);
            msg.title = title;
            byte[] thumb = SocialUtils.getHtmlByteArray(thumbnail);
            if (null != thumb)
                msg.thumbData = SocialUtils.compressBitmap(thumb, 32);
            else
                msg.thumbData = SocialUtils.compressBitmap(SocialUtils.getDefaultShareImage(context), 32);

            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = SocialUtils.buildTransaction("webpage");
            req.message = msg;
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            WeChat.getIWXAPIInstance(context, appId).sendReq(req);
        }
    }).start();

}
 
开发者ID:yangjie127,项目名称:ESSocialSDK-master,代码行数:26,代码来源:WeChatShareProxy.java

示例3: shareEmoticon

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public void shareEmoticon(Context context, String path, boolean isFriends) {
    if (api == null) {
        api = WXAPIFactory.createWXAPI(context, BuildConfig.WECHAT_APP_ID, false);
        api.registerApp(BuildConfig.WECHAT_APP_ID);
    }
    File file = new File(path);
    if (!file.exists()) {
        ToastUtil.show(context, "文件不存在");
        return;
    }
    WXEmojiObject emojiObject = new WXEmojiObject();
    emojiObject.emojiPath = path;
    WXMediaMessage msg = new WXMediaMessage(emojiObject);
    msg.description = "表情";
    //创建一个缩略图
    msg.thumbData = Util.bmpToByteArray(GlideBitmapFactory.decodeFile(path), true);
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = "emotion" + System.currentTimeMillis();
    req.message = msg;

    req.scene = isFriends ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    if (!api.sendReq(req)) {
        EventBus.getDefault().post(new EventShare(false));
        Toast.makeText(context, "分享表情失败", Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:27,代码来源:ShareManager.java

示例4: doInBackground

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
protected WXMediaMessage doInBackground() {
    WXMediaMessage msg = null;
    if (UMWXHandler.access$000(this.this$0).equals("emoji")) {
        msg = UMWXHandler.access$100(this.this$0);
    } else if (UMWXHandler.access$000(this.this$0).equals(Post.IMAGE_TYPE)) {
        msg = UMWXHandler.access$200(this.this$0);
    } else if (UMWXHandler.access$000(this.this$0).equals("music")) {
        msg = UMWXHandler.access$300(this.this$0);
    } else if (UMWXHandler.access$000(this.this$0).equals("text")) {
        msg = UMWXHandler.access$400(this.this$0);
    } else if (UMWXHandler.access$000(this.this$0).equals("text_image")) {
        msg = UMWXHandler.access$500(this.this$0);
    } else if (UMWXHandler.access$000(this.this$0).equals("video")) {
        msg = UMWXHandler.access$600(this.this$0);
    }
    byte[] datas = msg.thumbData;
    if (datas != null && datas.length > 32768) {
        Log.d("UMWXHandler", "原始缩略图大小 : " + (msg.thumbData.length / 1024) + " KB.");
        UMWXHandler.access$700(this.this$0).sendEmptyMessage(1);
        msg.thumbData = UMWXHandler.access$800(this.this$0, datas, 32768);
        Log.d("UMWXHandler", "压缩之后缩略图大小 : " + (msg.thumbData.length / 1024) + " KB.");
    }
    return msg;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:UMWXHandler$LoadResourceTask.java

示例5: shareToWX

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareToWX(final ShareInfo shareInfo, final int scene, Bitmap bitmap) {
    //构建一个WXWebpageObject对象,用于封装要分享的链接Url地址
    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = shareInfo.getLink();

    //构建一个WXMediaMessage对象,用于封装分享链接Url信息的标题与描述
    WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = shareInfo.getTitle();
    msg.description = shareInfo.getDesc();
    msg.thumbData = bitmap2Bytes(bitmap, 30);

    //构建一个微信请求
    SendMessageToWX.Req reqs = new SendMessageToWX.Req();
    reqs.message = msg;
    reqs.transaction = buildTransaction("webpage");
    reqs.scene = scene == 1 ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
    MyApplication.api.sendReq(reqs);
}
 
开发者ID:JunGeges,项目名称:AliZhiBoHao,代码行数:19,代码来源:ShareUtils.java

示例6: goToShowMsg

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void goToShowMsg(ShowMessageFromWX.Req showReq) {
    WXMediaMessage wxMsg = showReq.message;
    WXAppExtendObject obj = (WXAppExtendObject) wxMsg.mediaObject;

    StringBuffer msg = new StringBuffer(); // 组织一个待显示的消息内容
    msg.append("description: ");
    msg.append(wxMsg.description);
    msg.append("\n");
    msg.append("extInfo: ");
    msg.append(obj.extInfo);
    msg.append("\n");
    msg.append("filePath: ");
    msg.append(obj.filePath);

    Intent intent = new Intent(this, ShowFromWXActivity.class);
    intent.putExtra(Constants.ShowMsgActivity.STitle, wxMsg.title);
    intent.putExtra(Constants.ShowMsgActivity.SMessage, msg.toString());
    intent.putExtra(Constants.ShowMsgActivity.BAThumbData, wxMsg.thumbData);
    startActivity(intent);
    finish();
}
 
开发者ID:linsir6,项目名称:TripBuyer,代码行数:22,代码来源:WXEntryActivity.java

示例7: send

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private boolean send(String title, String content, String url, int iconResId, int scene) {

        if (wxapi.getWXAppSupportAPI() < 0x21020001) {
            return false;
        }

        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = url;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = title;
        msg.description = content;


        Bitmap bmp = BitmapFactory.decodeResource(BaseApplication.getContext().getResources(), iconResId);
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 150, 150, true);
        bmp.recycle();
        msg.thumbData = ImageUtil.bitmapToByteArray(thumbBmp, 100);

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("webpage");
        req.message = msg;
        req.scene = scene;

        // 调用api接口发送数据到微信
        return wxapi.sendReq(req);
    }
 
开发者ID:joy-inc,项目名称:joy-library,代码行数:27,代码来源:ShareWeixinUtil.java

示例8: genMsg

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static WXMediaMessage genMsg(WXMediaMessage.IMediaObject mediaObject
        , String description, String title
        , Bitmap thumbBmp) {
    if (null == mediaObject) {
        throw new RuntimeException("Please initialize the mediaObject");
    }
    if (TextUtils.isEmpty(description)) {
        throw new RuntimeException("Please set description.");
    }
    WXMediaMessage msg = new WXMediaMessage();
    msg.description = description;
    msg.mediaObject = mediaObject;
    if (!TextUtils.isEmpty(title)) {
        msg.title = title;
    }
    if (null != thumbBmp) {
        msg.thumbData = bmpToByteArray(thumbBmp, true);
    }
    return msg;
}
 
开发者ID:Jay-Y,项目名称:share,代码行数:21,代码来源:WxUtils.java

示例9: genRequest

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static BaseReq genRequest(WXMediaMessage msg, ShareTypeEnum type) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    switch (type) {
        case TEXT:
            req.transaction = buildTransaction("text");
            break;
        case MUSIC:
            req.transaction = buildTransaction("music");
            break;
        case VIDEO:
            req.transaction = buildTransaction("video");
            break;
        case IMAGE:
            req.transaction = buildTransaction("img");
            break;
    }
    req.message = msg;
    req.scene = SendMessageToWX.Req.WXSceneSession;
    return req;
}
 
开发者ID:Jay-Y,项目名称:share,代码行数:21,代码来源:WxUtils.java

示例10: sendText

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void sendText() {
    switch (instance.api) {
        case QQ:
            String appName = mContext.getString(R.string.app_name);
            Bundle params = QQUtils.genTextMsg(appName, title, description, qqTagetUrl, qqImgUrl);
            configInstance.getTencentApi().shareToQQ((Activity) mContext, params, new QQCallbackListener());
            return;
        case WeChat:
            // 初始化一个WXTextObject对象
            WXTextObject textObj = new WXTextObject();
            textObj.text = text;

            // 用WXTextObject对象初始化一个WXMediaMessage对象
            WXMediaMessage msg = WxUtils.genMsg(textObj, title, description);

            // 调用api接口发送数据到微信
            configInstance.getWxApi().sendReq(WxUtils.genRequest(msg, instance.type));
            return;
        case SinaWeiBo:
            return;
    }
}
 
开发者ID:Jay-Y,项目名称:share,代码行数:23,代码来源:ShareUtil.java

示例11: sendImage

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void sendImage() {
    switch (instance.api) {
        case QQ:
            String appName = mContext.getString(R.string.app_name);
            Bundle params = QQUtils.genImgMsg(appName, title, description, qqTagetUrl, qqImgUrl, qqFilePath);
            configInstance.getTencentApi().shareToQQ((Activity) mContext, params, new QQCallbackListener());
            return;
        case WeChat:
            WXImageObject imgObj = new WXImageObject();
            Bitmap thumbBmp = Bitmap.createScaledBitmap(wxImgBmp, THUMB_SIZE, THUMB_SIZE, true);
            wxImgBmp.recycle();
            WXMediaMessage msg = WxUtils.genMsg(imgObj, title, description, thumbBmp);

            // 调用api接口发送数据到微信
            configInstance.getWxApi().sendReq(WxUtils.genRequest(msg, instance.type));
            return;
        case SinaWeiBo:
            return;
    }
}
 
开发者ID:Jay-Y,项目名称:share,代码行数:21,代码来源:ShareUtil.java

示例12: shareObject

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static boolean shareObject(IMediaObject obj, String title, String desc, Bitmap thumb, int scene) {
    if (!isAppInstalled())
        return false;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = obj;
    msg.title = title;
    msg.description = desc;
    if (thumb != null) {
        thumb = BitmapHelper.clip(thumb, Scale.CenterCrop, 128, 128, 0);
        msg.thumbData = BitmapHelper.compressJPEG(thumb, 32 * 1024, 10);
    }

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.message = msg;
    req.scene = scene;

    return mWXApi.sendReq(req);
}
 
开发者ID:iWay7,项目名称:BikeHelper,代码行数:21,代码来源:WXApiHelper.java

示例13: shareText

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
/**
 * 无论是对话,还是朋友圈中,都只显示text字段,如果text中有链接,链接在对话和朋友圈中都可点击。
 *
 * @param title      这个字段传null就好,没有目前微信的SDK没有用到。
 * @param text       要分享的文本。
 * @param isTimeline 分享至微信聊天,还是朋友圈。true:分享至朋友圈;false:分享至微信聊天
 */
private void shareText(String title, String text, boolean isTimeline) {

    // 初始化一个WXTextObject对象
    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    // 用WXTextObject对象初始化一个WXMediaMessage对象
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    // 发送文本类型的消息时,title字段不起作用
    // msg.title = "Will be ignored";
    msg.title = title;
    msg.description = text;

    // 构造一个Req
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = ShareWechatUtils.buildTransaction("text"); // transaction字段用于唯一标识一个请求
    req.message = msg;
    req.scene = isTimeline ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;

    // 调用api接口发送数据到微信
    mAPI.sendReq(req);
}
 
开发者ID:markzhai,项目名称:AndroidProjectFrom0,代码行数:32,代码来源:WeChatSharePlugin.java

示例14: shareHypeLink

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
/**
 * 分享链接。在对话中,显示title,pic,description三个元素。在朋友圈中,显示title、pic两个元素。
 *
 * @param title      标题
 * @param text       朋友圈中不显示。
 * @param picPath    缩略图的本地路径
 * @param url        链接的地址
 * @param isTimeline 分享至微信聊天,还是朋友圈。true:分享至朋友圈;false:分享至微信聊天
 */
private void shareHypeLink(String title, String text, String picPath,
                           String url, int thumbNailSize, boolean isTimeline) {
    WXWebpageObject webPage = new WXWebpageObject();
    webPage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webPage);
    msg.title = title;
    msg.description = text;
    if (picPath != null) {
        Bitmap thumb = ShareWechatUtils.extractThumbNail(picPath,
                thumbNailSize, thumbNailSize, true);
        if (thumb != null) {
            Logger.e("Share:", "图片不为null");
            msg.setThumbImage(thumb);
        }
    }
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = ShareWechatUtils.buildTransaction("webpage");
    req.message = msg;
    req.scene = isTimeline ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;
    mAPI.sendReq(req);
}
 
开发者ID:markzhai,项目名称:AndroidProjectFrom0,代码行数:32,代码来源:WeChatSharePlugin.java

示例15: shareToWechat

import com.tencent.mm.sdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private static void shareToWechat(String transaction, Activity activity, String title, String summary, Bitmap img, int flag) {
    IWXAPI wxApi = getWxApi();

    WXImageObject imgObj = new WXImageObject(img);

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

    //Bitmap thumbBmp = Bitmap.createScaledBitmap(img, THUMB_SIZE, THUMB_SIZE, true);
    msg.thumbData = bmpToThumbArray(img);

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = transaction;
    req.message = msg;
    req.scene = flag;
    wxApi.sendReq(req);
}
 
开发者ID:qiujuer,项目名称:UPMiss,代码行数:18,代码来源:Share.java


注:本文中的com.tencent.mm.sdk.modelmsg.WXMediaMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。