qq_36790900
qq_36790900
采纳率10%
2017-03-06 06:37 阅读 2.8k

android中微信分享不显示Title,QQ分享要显示,怎么回事

ShareSDK.initSDK(context);
OnekeyShare oks = new OnekeyShare();
//关闭sso授权
oks.disableSSOWhenAuthorize();
String url = "http://www.zhongshezg.com/goods_"+goods_id+".htm";

    // title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
    oks.setTitle(shareJsonData.getString("goods_name").substring(0,9)+"...");
    // titleUrl是标题的网络链接,QQ和QQ空间等使用
    oks.setTitleUrl(url);
    // text是分享文本,所有平台都需要这个字段
    oks.setText("这个商品真是赞!"+url);
    // site是分享此内容的网站名称,仅在QQ空间使用
    oks.setSite(getString(R.string.app_name));
    // siteUrl是分享此内容的网站地址,仅在QQ空间使用
    oks.setSiteUrl(url);
    // 启动分享GUI
    oks.show(context);
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    qq_33700351 纯洁小码农_z 2017-03-08 02:58

    楼主,看完我的回复后,记得帮我删除我的答案,谢谢

    点赞 评论 复制链接分享
  • qq_27969037 Mr康 2017-03-06 08:50

    你是说你想要实现在微信分享的时候不显示标题,qq分享的时候要显示标题?

    点赞 评论 复制链接分享
  • qq_33700351 纯洁小码农_z 2017-03-08 02:43

    估计你写的时候有问题,你试试我的

     package com.nidoog.android.util;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.widget.Toast;
    
    import com.nidoog.android.R;
    import com.socks.library.KLog;
    import com.tencent.connect.share.QQShare;
    import com.tencent.mm.sdk.constants.Build;
    import com.tencent.tauth.IUiListener;
    import com.tencent.tauth.Tencent;
    import com.tencent.tauth.UiError;
    
    import cn.sharesdk.framework.Platform;
    import cn.sharesdk.framework.ShareSDK;
    import cn.sharesdk.sina.weibo.SinaWeibo;
    import cn.sharesdk.wechat.friends.Wechat;
    import cn.sharesdk.wechat.moments.WechatMoments;
    
    import static com.nidoog.android.app.App.sApi;
    
    /**
     * Created by lujiang on 2016/12/20 0020.
     * 分享工具类
     */
    
    public class ShareTool {
        //分享的类型:图片或者链接
        private Type type = null;
        //分享的渠道
        private Channel channel = null;
        //上下文
        private Activity context = null;
        //分享的文本内容(用于QQ, 短信)
        private String content = null;
        //分享的本地图片路径
        private String localImage = null;
        //分享的链接
        private String url = null;
        //分享的标题(用于QQ)
        private String title = null;
        //分享的远程图片地址(用于QQ)
        private String netImageUrl = null;
    
    
        public void setTitle(String title) {
            this.title = title;
        }
    
        public void setType(Type type) {
            this.type = type;
        }
    
        public void setChannel(Channel channel) {
            this.channel = channel;
        }
    
        public void setContext(Activity context) {
            this.context = context;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        public void setLocalImage(String localImage) {
            this.localImage = localImage;
        }
    
        public void setUrl(String url) {
            this.url = url;
        }
    
        public void setNetImageUrl(String netImageUrl) {
            this.netImageUrl = netImageUrl;
        }
    
        public ShareTool(Activity context){
            this.context = context;
        }
    
        @Override
        public String toString() {
            return "ShareTool{" +
                    "type=" + type +
                    ", channel=" + channel +
                    ", context=" + context +
                    ", content='" + content + '\'' +
                    ", localImage='" + localImage + '\'' +
                    ", url='" + url + '\'' +
                    ", title='" + title + '\'' +
                    ", netImageUrl='" + netImageUrl + '\'' +
                    '}';
        }
    
        public void share() {
    
            KLog.e("share >>>> " + this.toString());
    
            if (type == null) {
                ToastUtil.getInstance().show("分享类型不能为空");
                return;
            }
    
            if (channel == null) {
                ToastUtil.getInstance().show("分享途径不能为空");
                return;
            }
    
            if (context == null) {
                ToastUtil.getInstance().show("context不能为空");
                return;
            }
    
            doShare();
        }
    
        private void doShare() {
            //如果是短信
            if (channel == Channel.SMS) {
                shareSMS();
            } else if (channel == Channel.QQ) {
                shareQQ();
            } else if (channel == Channel.WEIXIN) {
                if(!isInstallWeixin()){
                    ToastUtil.getInstance().show(context.getString(R.string.instalWX));
                    return;
                }
                shareWeixin();
            } else if (channel == Channel.WECHAT_MOMENTS) {
                shareWechatMoments();
            }else if(channel == Channel.WEIBO){
                shareWeibo();
            }
        }
    
        /**
         * 分享到短信
         */
        private void shareSMS() {
            Intent it = new Intent(Intent.ACTION_VIEW);
            it.putExtra("sms_body", content);
            it.setType("vnd.android-dir/mms-sms");
            context.startActivity(it);
        }
    
        /**
         * 分享到QQ
         */
        private void shareQQ() {
    
            Tencent mTencent = Tencent.createInstance("1105393517", context);
    
            Bundle params = new Bundle();
            if (type == Type.TYPE_URL) {
                params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
                params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, url);
                params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, netImageUrl);
                params.putString(QQShare.SHARE_TO_QQ_SUMMARY, content);
                params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
            } else {
                params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, localImage);
                params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
            }
    
            params.putString(QQShare.SHARE_TO_QQ_APP_NAME, context.getString(R.string.app_name));
    
            mTencent.shareToQQ(context, params, new IUiListener() {
                @Override
                public void onComplete(Object o) {
    
                }
    
                @Override
                public void onError(UiError uiError) {
                    ToastUtil.getInstance().show(uiError.errorMessage);
                }
    
                @Override
                public void onCancel() {
    
                }
            });
        }
    
        /**
         * 分享到微信好友
         */
        private void shareWeixin() {
            Wechat.ShareParams wechatParams = new Wechat.ShareParams();
            if (type == Type.TYPE_URL) {
                wechatParams.setShareType(Platform.SHARE_WEBPAGE);
                wechatParams.url = url;
                wechatParams.title = title;
                wechatParams.text = content;
            } else {
                wechatParams.setImagePath(localImage);
                wechatParams.setShareType(Platform.SHARE_IMAGE);
            }
    
            Platform platform = ShareSDK.getPlatform(Wechat.NAME);
            platform.share(wechatParams);
        }
    
        /**
         * 分享到朋友圈
         */
        private void shareWechatMoments() {
            WechatMoments.ShareParams momentsParams = new WechatMoments.ShareParams();
            if (type == Type.TYPE_URL) {
                momentsParams.setShareType(Platform.SHARE_WEBPAGE);
                momentsParams.url = url;
                momentsParams.title = content;
                momentsParams.imageUrl = netImageUrl;
                momentsParams.text = content;
            } else {
                momentsParams.setImagePath(localImage);
                momentsParams.setShareType(Platform.SHARE_IMAGE);
            }
    
            Platform platform = ShareSDK.getPlatform(WechatMoments.NAME);
            platform.share(momentsParams);
        }
    
        /**
         * 分享到微博
         */
        private void shareWeibo(){
            SinaWeibo.ShareParams weiboParams = new SinaWeibo.ShareParams();
            if (type == Type.TYPE_URL) {
                weiboParams.setShareType(Platform.SHARE_WEBPAGE);
                weiboParams.text = url;
            } else {
                weiboParams.setImagePath(localImage);
                weiboParams.setShareType(Platform.SHARE_IMAGE);
            }
    
            Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
            weibo.share(weiboParams);
        }
    
        private boolean isInstallWeixin(){
            return sApi.getWXAppSupportAPI()  >= Build.PAY_SUPPORTED_SDK_INT;
        }
        /**
         * 分享方式
         */
        public enum Type {
            TYPE_IMAGE, //图片
            TYPE_URL //链接
        }
    
        public enum Channel {
            QQ, //QQ
            WEIXIN,//微信好友
            WECHAT_MOMENTS,//朋友圈
            WEIBO,//微博
            SMS,//短信
        }
    
    }
      public void shareWX_frrend(SendMessageEntity sendMessageEntity) {
            ShareTool shareTool = new ShareTool(this);
            shareTool.setType(ShareTool.Type.TYPE_URL);
            shareTool.setTitle("!");
            shareTool.setContent(sendMessageEntity.getData().getMessage());
            shareTool.setUrl("");
            shareTool.setChannel(ShareTool.Channel.WEIXIN);
            shareTool.share();
        }   public void shareQQ(SendMessageEntity followEntity) {
            ShareTool shareTool = new ShareTool(this);
            shareTool.setType(ShareTool.Type.TYPE_URL);
            shareTool.setTitle("");
            shareTool.setContent(followEntity.getData().getMessage());
            shareTool.setUrl("");
            shareTool.setChannel(ShareTool.Channel.QQ);
            shareTool.setNetImageUrl("");
            shareTool.share();
        }
    
    点赞 评论 复制链接分享

相关推荐