當前位置: 首頁>>代碼示例>>Java>>正文


Java SendMessageToWX類代碼示例

本文整理匯總了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();

}
 
開發者ID:yangjie127,項目名稱:ESSocialSDK-master,代碼行數:27,代碼來源:WeChatShareProxy.java

示例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();

}
 
開發者ID:yangjie127,項目名稱:ESSocialSDK-master,代碼行數:26,代碼來源:WeChatShareProxy.java

示例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;
        }
    }
}
 
開發者ID:yangjie127,項目名稱:ESSocialSDK-master,代碼行數:17,代碼來源:WeChatShareProxy.java

示例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();
    }
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:27,代碼來源:ShareManager.java

示例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();
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:21,代碼來源:OpenBuilder.java

示例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);
}
 
開發者ID:JunGeges,項目名稱:AliZhiBoHao,代碼行數:19,代碼來源:ShareUtils.java

示例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);
    }
 
開發者ID:joy-inc,項目名稱:joy-library,代碼行數:27,代碼來源:ShareWeixinUtil.java

示例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;
}
 
開發者ID:Jay-Y,項目名稱:share,代碼行數:21,代碼來源:WxUtils.java

示例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);
}
 
開發者ID:iWay7,項目名稱:BikeHelper,代碼行數:21,代碼來源:WXApiHelper.java

示例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);
}
 
開發者ID:markzhai,項目名稱:AndroidProjectFrom0,代碼行數:32,代碼來源:WeChatSharePlugin.java

示例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);
}
 
開發者ID:markzhai,項目名稱:AndroidProjectFrom0,代碼行數:32,代碼來源:WeChatSharePlugin.java

示例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);
}
 
開發者ID:qiujuer,項目名稱:UPMiss,代碼行數:18,代碼來源:Share.java

示例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);
}
 
開發者ID:leleliu008,項目名稱:Newton_for_Android_AS,代碼行數:28,代碼來源:ShareUtils.java

示例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);
    }
 
開發者ID:henjue,項目名稱:sharesdk,代碼行數:20,代碼來源:WechatShareManager.java

示例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);

}
 
開發者ID:henjue,項目名稱:sharesdk,代碼行數:17,代碼來源:WechatShareManager.java


注:本文中的com.tencent.mm.sdk.modelmsg.SendMessageToWX類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。