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


Java SendMessageToWX.Req方法代码示例

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


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

示例1: shareEmoticon

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例2: shareToWX

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例3: send

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例4: genRequest

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例5: shareObject

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例6: shareText

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例7: shareHypeLink

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例8: shareToWechat

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的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

示例9: shareToWX

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
/**
 * 分享到微信
 */
static void shareToWX(Activity activity, int which, ShareContent shareContent) {
	WXWebpageObject webpage = new WXWebpageObject();
	webpage.webpageUrl = shareContent.getLinkUrl();
	
	WXMediaMessage msg = new WXMediaMessage(webpage);
	msg.title = shareContent.getTitle();
	msg.description = shareContent.getSummary();
	Bitmap thumb = BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_logo);
	msg.thumbData = BitmapUtil.compress(thumb, CompressFormat.PNG);
	
	SendMessageToWX.Req req = new SendMessageToWX.Req();
	req.transaction = buildTransaction("webpage");
	req.message = msg;
	
	if (1 == which) {
		msg.title = shareContent.getSummary();
		req.scene = SendMessageToWX.Req.WXSceneTimeline;
	} else if (0 == which) {
		req.scene = SendMessageToWX.Req.WXSceneSession;
	}
	
	IWXAPI api = MyApp.getApp().getWXAPI();
	api.sendReq(req);
}
 
开发者ID:leleliu008,项目名称:Newton_for_Android_AS,代码行数:28,代码来源:ShareUtils.java

示例10: shareText

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void shareText(int shareType, Message.Text message) {

        String text = message.getContent();
        //初始化一个WXTextObject对象
        WXTextObject textObj = new WXTextObject();
        textObj.text = text;
        //用WXTextObject对象初始化一个WXMediaMessage对象
        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = textObj;
        msg.description = text;
        //构造一个Req
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        //transaction字段用于唯一标识一个请求
        req.transaction = ShareUtil.buildTransaction("textshare");
        req.message = msg;
        //发送的目标场景, 可以选择发送到会话 WXSceneSession 或者朋友圈 WXSceneTimeline。 默认发送到会话。
        req.scene = shareType;
        mIWXAPI.sendReq(req);
    }
 
开发者ID:henjue,项目名称:sharesdk,代码行数:20,代码来源:WechatShareManager.java

示例11: sharePicture

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void sharePicture(int shareType, Message.Picture message) {
    Bitmap bitmap = message.getImage();
    Bitmap thumbImage = Bitmap.createScaledBitmap(bitmap, THUMB_SIZE, THUMB_SIZE, false);
    WXImageObject imgObj = new WXImageObject(bitmap);
    WXMediaMessage msg = new WXMediaMessage();
    msg.mediaObject = imgObj;
    if (thumbImage != null) {
        msg.setThumbImage(thumbImage);
    }
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = ShareUtil.buildTransaction("imgshareappdata");
    req.message = msg;
    req.scene = shareType;
    mIWXAPI.sendReq(req);

}
 
开发者ID:henjue,项目名称:sharesdk,代码行数:17,代码来源:WechatShareManager.java

示例12: shareWebPage

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void shareWebPage(int shareType, Message.Web message) {

        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = message.getURL();
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = message.getTitle();
        msg.description = message.getDescription();

        Bitmap bmp = Bitmap.createScaledBitmap(message.getImage(), THUMB_SIZE, THUMB_SIZE, true);
        if (bmp == null) {
            Toast.makeText(mContext, R.string.share_pic_empty,
                    Toast.LENGTH_SHORT).show();
        } else {
            msg.setThumbImage(bmp);
        }

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = ShareUtil.buildTransaction("webpage");
        req.message = msg;
        req.scene = shareType;
        mIWXAPI.sendReq(req);
    }
 
开发者ID:henjue,项目名称:sharesdk,代码行数:23,代码来源:WechatShareManager.java

示例13: shareMusic

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void shareMusic(int shareType, Message.Music message) {

        WXMusicObject music = new WXMusicObject();
        //Str1+"#wechat_music_url="+str2 ;str1是网页地址,str2是音乐地址。

        music.musicUrl = message.getURL() + "#wechat_music_url=" + message.getMusicUrl();
        WXMediaMessage msg = new WXMediaMessage(music);
        msg.title = message.getTitle();
        msg.description = message.getDescription();

        Bitmap thumb = Bitmap.createScaledBitmap(message.getImage(), THUMB_SIZE, THUMB_SIZE, true);
        if (thumb == null) {
            Toast.makeText(mContext, R.string.share_pic_empty,
                    Toast.LENGTH_SHORT).show();
        } else {
            msg.setThumbImage(thumb);
        }

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = ShareUtil.buildTransaction("music");
        req.message = msg;
        req.scene = shareType;
        mIWXAPI.sendReq(req);
    }
 
开发者ID:henjue,项目名称:sharesdk,代码行数:25,代码来源:WechatShareManager.java

示例14: sendImage

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
private void sendImage(int type, Bitmap bitmap) {
    Bitmap thumb = getThumbBitmap(bitmap);

    WXImageObject imageObject = new WXImageObject(bitmap);
    WXMediaMessage msg = new WXMediaMessage(imageObject);
    msg.title = mShareOption.title;
    msg.description = mShareOption.description;
    msg.thumbData = Utils.bmpToByteArray(thumb, true);

    SendMessageToWX.Req request = new SendMessageToWX.Req();
    request.transaction = "image" + System.currentTimeMillis();
    request.message = msg;
    request.scene = type;

    mWXAPI.sendReq(request);
}
 
开发者ID:chenjishi,项目名称:wiping,代码行数:17,代码来源:ShareDialog.java

示例15: share

import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入方法依赖的package包/类
@Override
public void share() {
    if (App.getWechatAppId() == null) {
        if (mListener != null) {
            mListener.onError(this);
        }
    }
    IWXAPI api = WXAPIFactory.createWXAPI(mContext, App.getWechatAppId(), false);
    if (!api.isWXAppInstalled()) {
        if (mListener != null) {
            mListener.onError(this);
        }
        return;
    }
    WXWebpageObject web = new WXWebpageObject();
    web.webpageUrl = mUrl;
    WXMediaMessage msg = new WXMediaMessage(web);
    msg.title = mTitle;
    msg.description = mText;
    msg.thumbData = AppUtil.toByteArray(AppUtil.getAppIcon(mContext));
    SendMessageToWX.Req req = new SendMessageToWX.Req();
    req.transaction = TRANSACTION + System.currentTimeMillis();
    req.message = msg;
    req.scene = getScene();
    api.sendReq(req);
}
 
开发者ID:wavinsun,项目名称:MUtils,代码行数:27,代码来源:ShareWechatImpl.java


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