本文整理汇总了Java中com.tencent.mm.sdk.modelmsg.SendMessageToWX类的典型用法代码示例。如果您正苦于以下问题:Java SendMessageToWX类的具体用法?Java SendMessageToWX怎么用?Java SendMessageToWX使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SendMessageToWX类属于com.tencent.mm.sdk.modelmsg包,在下文中一共展示了SendMessageToWX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shareToWeChat
import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入依赖的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();
}
示例2: shareToWeChatTimeline
import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入依赖的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();
}
示例3: shareComplete
import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
public static void shareComplete(SendMessageToWX.Resp resp) {
if (null != mCallback) {
switch (resp.errCode) {
case BaseResp.ErrCode.ERR_OK:
mCallback.onSuccess();
break;
case BaseResp.ErrCode.ERR_USER_CANCEL:
mCallback.onCancel();
break;
case BaseResp.ErrCode.ERR_AUTH_DENIED:
default:
mCallback.onFailure(new Exception("BaseResp.ErrCode.ERR_AUTH_DENIED"));
break;
}
}
}
示例4: 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();
}
}
示例5: share
import com.tencent.mm.sdk.modelmsg.SendMessageToWX; //导入依赖的package包/类
/**
* 单纯分享图片
*/
private void share(Bitmap bitmap, int scene) {
try {
String url = saveShare(bitmap);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
Uri uri = FileProvider.getUriForFile(activity,"net.oschina.app.provider",new File(url));
intent.putExtra(Intent.EXTRA_STREAM, uri);//uri为你要分享的图片的uri
intent.setType("image/*");
intent.setClassName("com.tencent.mm", scene == SendMessageToWX.Req.WXSceneTimeline ?
"com.tencent.mm.ui.tools.ShareToTimeLineUI"
: "com.tencent.mm.ui.tools.ShareImgUI");
activity.startActivityForResult(intent, 1);
}catch (Exception e){
e.printStackTrace();
Toast.makeText(activity,"请安装微信",Toast.LENGTH_SHORT).show();
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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;
}
示例9: 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);
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}