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;
                            }
                        }
                    });
                }
            });
  • 相关阅读:
    springcloud中常用的注解
    MySQL--Profiling和Trace使用
    MySQL Execution Plan--IN查询计划
    MySQL Config--参数system_time_zone和参数time_zone
    MySQL Replication--全局参数gtid_executed和gtid_purged
    MySQL Transaction--事务无法正常回滚导致的异常
    MySQL Execution Plan--数据排序操作
    MySQL Session--批量KILL会话
    MySQL Transaction--MySQL与SQL Server在可重复读事务隔离级别上的差异
    MySQL Transaction--事务相关查询
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4755167.html
Copyright © 2011-2022 走看看