写点什么

Android 使用微信开放平台分享内容到微信,apm 性能监控系统

发布于: 22 小时前

注册微信接口:

private IWXAPI weApi;


private boolean isRegSuccess = false;


// (Context context, String appId)


weApi = WXAPIFactory.createWXAPI(this, null);


isRegSuccess = weApi.registerApp(Constant.WeChat.APP_ID);


Log.v(Constant.TAG, "isRegSuccess:" + isRegSuccess);

发送文字到微信:

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("text");


req.message = msg;


req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline


: SendMessageToWX.Req.WXSceneSession;


api.sendReq(req);

发送图片到微信

WXImageObject imgObj = new WXImageObject(


bmp);


WXMediaMessage msg = new WXMediaMessage();


msg.mediaObject = imgObj;


Bitmap thumbBmp = Bitmap


.createScaledBitmap(bmp,


THUMB_SIZE,


THUMB_SIZE, true);


bmp.recycle();


msg.thumbData = WeChatUtil


.bmpToByteArray(thumbBmp,


true);


SendMessageToWX.Req req = new SendMessageToWX.Req();


req.transaction = buildTransaction("img");


req.message = msg;


req.scene = isTimelineCb


.isChecked() ? SendMessageToWX.Req.WXSceneTimeline


: SendMessageToWX.Req.WXSceneSession;


api.sendReq(req);

发送音乐

WXMusicObject music = new WXMusicObject();


// music.musicUrl =


// "http://www.baidu.com";


music.musicUrl = "http://staff


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


2.ustc.edu.cn/~wdw/softdown/index.asp/0042515_05.ANDY.mp3";


// music.musicUrl="http://120.196.211.49/XlFNM14sois/AKVPrOJ9CBnIN556OrWEuGhZvlDF02p5zIXwrZqLUTti4o6MOJ4g7C6FPXmtlh6vPtgbKQ==/31353278.mp3";


WXMediaMessage msg = new WXMediaMessage();


msg.mediaObject = music;


msg.title = "title ";


msg.description = "description ";


Bitmap thumb = BitmapFactory


.decodeResource(


getResources(),


R.drawable.send_music_thumb);


msg.thumbData = WeChatUtil


.bmpToByteArray(thumb, true);


SendMessageToWX.Req req = new SendMessageToWX.Req();


req.transaction = buildTransaction("music");


req.message = msg;


req.scene = isTimelineCb


.isChecked() ? SendMessageToWX.Req.WXSceneTimeline


: SendMessageToWX.Req.WXSceneSession;


api.sendReq(req);

发送视频

WXVideoObject video = new WXVideoObject();


video.videoUrl = "http://www.baidu.com";


WXMediaMessage msg = new WXMediaMessage(


video);


msg.title = "Video Title";


msg.description = "Video Description";


Bitmap thumb = BitmapFactory


.decodeResource(


getResources(),


R.drawable.send_music_thumb);


msg.thumbData = WeChatUtil


.bmpToByteArray(thumb, true);


SendMessageToWX.Req req = new SendMessageToWX.Req();


req.transaction = buildTransaction("video");


req.message = msg;


req.scene = isTimelineCb


.isChecked() ? SendMessageToWX.Req.WXSceneTimeline


: SendMessageToWX.Req.WXSceneSession;


api.sendReq(req);

发送网页

WXWebpageObject webpage = new WXWebpageObject();


webpage.webpageUrl = "http://www.baidu.com";


WXMediaMessage msg = new WXMediaMessage(


webpage);


msg.title = "WebPage Title";

评论

发布
暂无评论
Android 使用微信开放平台分享内容到微信,apm性能监控系统