Android:微信分享(好友、朋友圈、收藏)图片信息

使用微信官方自带的SDK实现图片分享

记得用 填写在微信开放平台的签名 打包

不要调换代码的顺序!!!

private static final int THUMB_SIZE = 150;//使用的参数

//第一个参数为 上下文 记得传
public static void shareText(Context context,int sceneFlag) {

        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);

        WXImageObject imgObj = new WXImageObject(bmp);
        WXMediaMessage msg = new WXMediaMessage();
        msg.mediaObject = imgObj;

        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 = "img"+String.valueOf(System.currentTimeMillis());
        req.message = msg;
        switch (sceneFlag){
            case 0://分享到聊天界面
                req.scene = SendMessageToWX.Req.WXSceneSession;
                break;
            case 1://分享到朋友圈
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
                break;
            case 2://添加到收藏
                req.scene = SendMessageToWX.Req.WXSceneFavorite;
                break;
        }
        api.sendReq(req);
}

官网地址:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317340&token=&lang=zh_CN

你可能感兴趣的:(学习)