zoukankan      html  css  js  c++  java
  • 微信朋友圈如何同时分享(图片+文字)

    微信朋友圈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);
        }
    }

    分享图片和文字代码:

    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);
    应该很详细了吧

    官方:

    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;
                            }
                        }
                    });
                }
            });
  • 相关阅读:
    二分优化lis和STL函数
    D8 双连通分量
    Apicloud 之按两次后退键退出应用
    Js 之正则验证手机号、QQ、身份证等
    PHP 之循环创建文件夹
    招聘系统
    Mysql 之根据经纬度按距离排序
    PHP 之根据两个经纬度计算距离
    PHP 之Mysql优化
    Tkinter 之使用PAGE工具开发GUI界面
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4755167.html
Copyright © 2011-2022 走看看