以下是:微信朋友圈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);
}
}
android微信分享 朋友圈分享
------解决方案--------------------
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);
应该很详细了吧