80,351
社区成员
发帖
与我相关
我的任务
分享
public IWXAPI api;
...
api = WXAPIFactory.createWXAPI(this, "wx27154ac8a3dd5ba8",true);
api.registerApp("wx27154ac8a3dd5ba8");
api.handleIntent(getIntent(), this);
boolean sendReq = sendByWX(api, content, shareimg, true);//这个你自己写我是根据我的要求写的
...
private boolean sendByWX( final IWXAPI api,
String shareContent,
UMediaObject shareImage,
boolean toCircle) {
WXWebpageObject webpage = new WXWebpageObject();//我的是图文分享,你可以根据你的需要设置
//为什么需要填写url? 当前Demo使用的微信SDK不支持图文分享,使用图文分享必须转成URL分享,所以需要填写一个URL
webpage.webpageUrl = fenXiangUrl;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = content;
msg.description = content;
if (shareImage != null && shareImage.getMediaType() == MediaType.IMAGE) {
byte[] b = shareImage.toByte();
if (b != null) {
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
bmp.recycle();
msg.thumbData = Util.bmpToByteArray(thumbBmp, true); // 设置缩略图
}
}
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = toCircle ? SendMessageToWX.Req.WXSceneTimeline
: SendMessageToWX.Req.WXSceneSession;
boolean sendReq = api.sendReq(req);
return sendReq;
}
private String buildTransaction(final String type) {
return (type == null) ? String.valueOf(System.currentTimeMillis())
: type + System.currentTimeMillis();
}
这些我觉得都不是很重要,在文档里面都能看到,主要是签名那块要是操作不好会出现分享不出去的问题,http://open.weixin.qq.com/document/gettingstart/android/?lang=zh_CN
要获取返回值的话还得自己加东西,文档里面有很简单,希望帮到你