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


Java WXMediaMessage类代码示例

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


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

示例1: shareToWX

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
/**
 * @param flag
 * 0 发送到会话
 * 1 发送到朋友圈
 */
private int shareToWX(int flag){
    String text = mDetailItem.getUserName()+"说: "+mDetailItem.getRantContent()+" " + "\n目前有"+mDetailItem.getCommentList().size()+"人围观,来凑个热闹吧!";
    final IWXAPI iwxapi = WXAPIFactory.createWXAPI(this, getString(R.string.app_id));
    iwxapi.registerApp(getString(R.string.app_id));
    if(!iwxapi.isWXAppInstalled()){
        Toast.makeText(this, "你还没有安装微信", Toast.LENGTH_SHORT).show();
        return 0;
    }

    WXWebpageObject webpage = new WXWebpageObject();
    webpage.webpageUrl = getString(R.string.ip_server)+"rant.action?rantId="+mDetailItem.getRantId();
    final WXMediaMessage msg = new WXMediaMessage(webpage);
    msg.title = "Rant社区";
    msg.description = text;

    final SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = String.valueOf(System.currentTimeMillis());
    req.scene = flag;
    final Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    msg.setThumbImage(logo);
    req.message = msg;
    iwxapi.sendReq(req);
    return 1;
}
 
开发者ID:shawnsky,项目名称:RantApp,代码行数:30,代码来源:RantActivity.java

示例2: share

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void share(final int shareId) {
    mapObject.captureMap(new IMapCaptureFinished() {
        @Override
        public void onMapCaptureFinished(Bitmap bitmap, int status) {
            WXImageObject imageObject = new WXImageObject(bitmap);

            WXMediaMessage mediaMessage = new WXMediaMessage();
            mediaMessage.mediaObject = imageObject;
            Bitmap thumb = Bitmap.createScaledBitmap(bitmap,50,50,true);
            bitmap.recycle();
            mediaMessage.thumbData = ShareUtils.bmpToByteArray(thumb,true);
            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = ShareUtils.buildTransaction("img");
            req.message = mediaMessage;
            if(shareId == R.id.btn_share_to_friend){
                req.scene = SendMessageToWX.Req.WXSceneSession;
            }
            else{
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
            }
            CFLog.e("Share","send = "+ mWxApi.sendReq(req));
        }
    });
}
 
开发者ID:stdnull,项目名称:RunMap,代码行数:26,代码来源:TrackPresenterImpl.java

示例3: shareWeb

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareWeb(Context context,String title,String desc,String url,@Scene int scene){
    if (!checkForSupport(context)) return;
    WXWebpageObject webPage = new WXWebpageObject();
    webPage.webpageUrl = url;
    WXMediaMessage msg = new WXMediaMessage(webPage);
    msg.title = title;
    msg.description = desc;
    Bitmap thumb = BitmapFactory.decodeResource(context.getResources(), R.mipmap.app_icon_64);
    msg.thumbData = bmpToByteArray(thumb);

    // 如果分享到朋友圈需要校验是否支持
    if (scene == SendMessageToWX.Req.WXSceneTimeline && !checkTimeLine(context)) return;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction(scene);
    req.message = msg;
    req.scene = scene;
    boolean sendReq = api.sendReq(req);
}
 
开发者ID:WeGdufe,项目名称:MovingGdufe-Android,代码行数:20,代码来源:ShareUtils.java

示例4: shareImage

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void shareImage(final int shareTarget, String desc, final String localPath, byte[] thumbData) {
    if (shareTarget == Target.SHARE_WX_FRIENDS) {
        if (FileUtils.isGifFile(localPath)) {
            LogUtils.e(TAG, "发送给朋友时 Gif 文件以emoji格式分享");
            WXEmojiObject emoji = new WXEmojiObject();
            emoji.emojiPath = localPath;
            WXMediaMessage msg = new WXMediaMessage();
            msg.mediaObject = emoji;
            msg.description = desc;
            //这个值似乎有限制,太大无法发送,所有已使用低质量压缩
            msg.thumbData = thumbData;
            sendMsgToWx(msg, shareTarget, "emoji");
        } else {
            shareImage(shareTarget, localPath, thumbData);
        }
    } else {
        shareImage(shareTarget, localPath, thumbData);
    }
}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:20,代码来源:WxPlatform.java

示例5: shareWeb

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void shareWeb(final int shareTarget, Activity activity, final ShareObj obj) {
    BitmapUtils.getStaticSizeBitmapByteByPathTask(obj.getThumbImagePath(), THUMB_IMAGE_SIZE)
            .continueWith(new ThumbDataContinuation(TAG, "shareWeb", mOnShareListener) {
                @Override
                public void onSuccess(byte[] thumbData) {
                    WXWebpageObject webPage = new WXWebpageObject();
                    webPage.webpageUrl = obj.getTargetUrl();
                    WXMediaMessage msg = new WXMediaMessage(webPage);
                    msg.title = obj.getTitle();
                    msg.description = obj.getSummary();
                    msg.thumbData = thumbData;
                    sendMsgToWx(msg, shareTarget, "web");
                }
            }, Task.UI_THREAD_EXECUTOR);

}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:18,代码来源:WxPlatform.java

示例6: shareMusic

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void shareMusic(final int shareTarget, Activity activity, final ShareObj obj) {
    BitmapUtils.getStaticSizeBitmapByteByPathTask(obj.getThumbImagePath(), THUMB_IMAGE_SIZE)
            .continueWith(new ThumbDataContinuation(TAG, "shareMusic", mOnShareListener) {
                @Override
                public void onSuccess(byte[] thumbData) {
                    WXMusicObject music = new WXMusicObject();
                    music.musicUrl = obj.getMediaPath();
                    WXMediaMessage msg = new WXMediaMessage();
                    msg.mediaObject = music;
                    msg.title = obj.getTitle();
                    msg.description = obj.getSummary();
                    msg.thumbData = thumbData;
                    sendMsgToWx(msg, shareTarget, "music");
                }
            }, Task.UI_THREAD_EXECUTOR);

}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:19,代码来源:WxPlatform.java

示例7: shareVideo

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void shareVideo(final int shareTarget, Activity activity, final ShareObj obj) {
    if (obj.isShareByIntent() && shareTarget == Target.SHARE_WX_FRIENDS) {
        try {
            IntentShareUtils.shareVideo(activity, obj.getMediaPath(), SocialConstants.WECHAT_PKG, SocialConstants.WX_FRIEND_PAGE);
        } catch (Exception e) {
            this.mOnShareListener.onFailure(new SocialException(SocialException.CODE_SHARE_BY_INTENT_FAIL, e));
        }
    } else {
        BitmapUtils.getStaticSizeBitmapByteByPathTask(obj.getThumbImagePath(), THUMB_IMAGE_SIZE)
                .continueWith(new ThumbDataContinuation(TAG, "shareVideo", mOnShareListener) {
                    @Override
                    public void onSuccess(byte[] thumbData) {
                        WXVideoObject video = new WXVideoObject();
                        video.videoUrl = obj.getMediaPath();
                        WXMediaMessage msg = new WXMediaMessage(video);
                        msg.title = obj.getTitle();
                        msg.description = obj.getSummary();
                        msg.thumbData = thumbData;
                        sendMsgToWx(msg, shareTarget, "video");
                    }
                }, Task.UI_THREAD_EXECUTOR);
    }

}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:26,代码来源:WxPlatform.java

示例8: shareText

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
protected void shareText(final ShareParamText params) throws ShareException {
    String text = params.getContent();
    if (TextUtils.isEmpty(text)) {
        throw new InvalidParamException("Content is empty or illegal");
    }

    WXTextObject textObj = new WXTextObject();
    textObj.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction("textshare");
    req.message = msg;
    req.scene = getShareType();
    Log.d(TAG, "start share text");
    shareOnMainThread(req);
}
 
开发者ID:Bilibili,项目名称:BiliShare,代码行数:22,代码来源:BaseWxShareHandler.java

示例9: shareImage

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
protected void shareImage(final ShareParamImage params) throws ShareException {
    mImageHelper.downloadImageIfNeed(params, new Runnable() {
        @Override
        public void run() {
            WXImageObject imgObj = buildWXImageObject(params.getImage());

            WXMediaMessage msg = new WXMediaMessage();
            msg.mediaObject = imgObj;
            msg.thumbData = mImageHelper.buildThumbData(params.getImage());

            final SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = buildTransaction("imgshareappdata");
            req.message = msg;
            req.scene = getShareType();
            Log.d(TAG, "start share image");
            shareOnMainThread(req);
        }
    });
}
 
开发者ID:Bilibili,项目名称:BiliShare,代码行数:21,代码来源:BaseWxShareHandler.java

示例10: sendMsgToWx

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void sendMsgToWx(WXMediaMessage msg, int shareTarget, String sign) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = buildTransaction(sign);
    req.message = msg;
    req.scene = getShareToWhere(shareTarget);
    boolean sendResult = mWxApi.sendReq(req);
    if (!sendResult) {
        mOnShareListener.onFailure(new SocialException("sendMsgToWx失败,可能是参数错误"));
    }
}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:11,代码来源:WxPlatform.java

示例11: shareText

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void shareText(int shareTarget, Activity activity, ShareObj obj) {
    WXTextObject textObj = new WXTextObject();
    textObj.text = obj.getSummary();
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = textObj;
    msg.title = obj.getTitle();
    msg.description = obj.getSummary();
    sendMsgToWx(msg, shareTarget, "text");
}
 
开发者ID:chendongMarch,项目名称:SocialSdkLibrary,代码行数:11,代码来源:WxPlatform.java

示例12: shareText

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareText(Context context, String scene) {

        //注册微信
        registerWX(context);
        //构建文本分享消息并发送分享
        WXTextObject wxTextObject = new WXTextObject();
        wxTextObject.text = "你好";

        WXMediaMessage message = new WXMediaMessage();
        message.mediaObject = wxTextObject;
        message.description ="随便逛逛";

        //构造一个REQ
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("text");
        req.message = message;

        if (scene.equalsIgnoreCase("session")) {
            req.scene = SendMessageToWX.Req.WXSceneSession;
        } else if (scene.equalsIgnoreCase("timeline")) {
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
        } else if (scene.equalsIgnoreCase("favorite")) {
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
        }

        //调用API接口
        api.sendReq(req);

    }
 
开发者ID:haihaio,项目名称:AmenWeather,代码行数:30,代码来源:WXEntryActivityUtils.java

示例13: shareText

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
@Override
public void shareText(int platform, String text, Activity activity, ShareListener listener) {
    WXTextObject textObject = new WXTextObject();
    textObject.text = text;

    WXMediaMessage message = new WXMediaMessage();
    message.mediaObject = textObject;
    message.description = text;

    sendMessage(platform, message, buildTransaction("text"));
}
 
开发者ID:beanu,项目名称:smart-farmer-android,代码行数:12,代码来源:WxShareInstance.java

示例14: sendMessage

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
private void sendMessage(int platform, WXMediaMessage message, String transaction) {
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = transaction;
    req.message = message;
    req.scene = platform == SharePlatform.WX_TIMELINE ? SendMessageToWX.Req.WXSceneTimeline
            : SendMessageToWX.Req.WXSceneSession;
    mIWXAPI.sendReq(req);
}
 
开发者ID:beanu,项目名称:smart-farmer-android,代码行数:9,代码来源:WxShareInstance.java

示例15: shareText

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage; //导入依赖的package包/类
public static void shareText(String text, SharePlace sharePlace) {
    WXTextObject wxTextObject = new WXTextObject();
    wxTextObject.text = text;

    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = wxTextObject;
    msg.description = text;

    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = WechatPayTools.getCurrTime();

    req.message = msg;
    switch (sharePlace) {
        case Friend:
            req.scene = SendMessageToWX.Req.WXSceneSession;
            break;
        case Zone:
            req.scene = SendMessageToWX.Req.WXSceneTimeline;
            break;
        case Favorites:
            req.scene = SendMessageToWX.Req.WXSceneFavorite;
            break;
    }

    if (iwxapi != null) {
        iwxapi.sendReq(req);
    } else {
        throw new NullPointerException("请先调用WechatShare.init()方法");
    }
}
 
开发者ID:vondear,项目名称:RxTools,代码行数:31,代码来源:WechatShareTools.java


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