以下是:微信朋友圈SDK 分享图片的代码,但只能分享图片,不能分享文字,如何才能图片和文字同时分享?求各位大神指教!
public class MainActivity extends Activity { private static final int THUMB_SIZE = 150; private static final String SDCARD_ROOT = Environment.getExternalStorageDirectory().getAbsolutePath(); private static final String APP_ID = "wx1b1ed04625409aa7"; private static final String tag = "MainActivity"; IWXAPI api = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); api = WXAPIFactory.createWXAPI(this, APP_ID, true); api.registerApp(APP_ID); sendImg(); } private void sendImg() { String imagePath = SDCARD_ROOT + "/test.png"; WXImageObject imgObj = new WXImageObject(); imgObj.setImagePath(imagePath); WXMediaMessage msg = new WXMediaMessage(); msg.mediaObject = imgObj; msg.description="图片描述"; Bitmap bmp = BitmapFactory.decodeFile(imagePath); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true); bmp.recycle(); msg.thumbData = Util.bmpToByteArray(thumbBmp, true); msg.title="abc-title"; SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = "img"+String.valueOf(System.currentTimeMillis()); req.message = msg; req.scene = SendMessageToWX.Req.WXSceneTimeline; api.sendReq(req); } }
回复讨论(解决方案)
试试WXMediaMessage api的description成员。
- (NSString*) description [read, write, retain]
描述内容
注意:
长度不能超过1K
msg.description="你需要的文字";
- (NSString*) description [read, write, retain]
描述内容
注意:
长度不能超过1K
msg.description="你需要的文字";
试试WXMediaMessage api的description成员。
- (NSString*) description [read, write, retain]
描述内容
注意:
长度不能超过1K
msg.description="你需要的文字";
- (NSString*) description [read, write, retain]
描述内容
注意:
长度不能超过1K
msg.description="你需要的文字";
这个好像是IOS的吧?而且上面我也是用的WXMediaMessage对象了嘛
WXWebpageObject webpage = new WXWebpageObject();
//为什么需要填写url? 当前Demo使用的微信SDK不支持图文分享,使用图文分享必须转成URL分享,所以需要填写一个URL
webpage.webpageUrl = fenXiangUrl;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = content;
msg.description = content;
操作图片 msg.thumbData;
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);
应该很详细了吧
//为什么需要填写url? 当前Demo使用的微信SDK不支持图文分享,使用图文分享必须转成URL分享,所以需要填写一个URL
webpage.webpageUrl = fenXiangUrl;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.title = content;
msg.description = content;
操作图片 msg.thumbData;
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);
应该很详细了吧
lulong1985 谢谢你! 果然看文档比我仔细多了,当然想的时候想得可能也比我多!
后来我也在官方的demo中找到了如下代码
谢谢你啦!
不过我现在用的友盟的SDK,友盟集成了QQ空间,QQ,微信,微信朋友圈,人人网,豆瓣网等..的SDK,里面包含了分享,登录,评论等功能,个人觉得还比较方便.
希望 能加 lulong1985你为QQ好友!
后来我也在官方的demo中找到了如下代码
findViewById(R.id.send_webpage).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MMAlert.showAlert(SendToWXActivity.this, getString(R.string.send_webpage), SendToWXActivity.this.getResources().getStringArray(R.array.send_webpage_item), null, new MMAlert.OnAlertSelectId(){ @Override public void onClick(int whichButton) { switch(whichButton){ case MMAlertSelect1: WXWebpageObject webpage = new WXWebpageObject(); webpage.webpageUrl = "http://www.baidu.com"; WXMediaMessage msg = new WXMediaMessage(webpage); msg.title = "WebPage Title WebPage Title WebPage Title WebPage Title WebPage Title WebPage Title WebPage Title WebPage Title WebPage Title Very Long Very Long Very Long Very Long Very Long Very Long Very Long Very Long Very Long Very Long"; msg.description = "WebPage Description WebPage Description WebPage Description WebPage Description WebPage Description WebPage Description WebPage Description WebPage Description WebPage Description Very Long Very Long Very Long Very Long Very Long Very Long Very Long"; Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.send_music_thumb); msg.thumbData = Util.bmpToByteArray(thumb, true); SendMessageToWX.Req req = new SendMessageToWX.Req(); req.transaction = buildTransaction("webpage"); req.message = msg; req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession; api.sendReq(req); finish(); break; default: break; } } }); } });
谢谢你啦!
不过我现在用的友盟的SDK,友盟集成了QQ空间,QQ,微信,微信朋友圈,人人网,豆瓣网等..的SDK,里面包含了分享,登录,评论等功能,个人觉得还比较方便.
希望 能加 lulong1985你为QQ好友!
多谢高人分享,很有用!
您好,我能问下,您是怎么分享到微信呢,我不会写这部分内容了