Android使用Mob ShareSDK 分享不同平台

Share分享,要注意的是,如果不能调用起微信相关,看看微信开发者平台是否添加正式,微信开发者正式之后,打正式包进行分享调用

 /*分享弹框*/
    private void showShare2() {
        OnekeyShare oks = new OnekeyShare();
        /*oks.addHiddenPlatform(QQ.NAME);
        oks.setImageData();*/
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
            @Override
            public void onShare(Platform platform, Platform.ShareParams paramsToShare) {
                Log.e("platform.getName()", "platform.getName():--------------------:" + platform.getName());
                if ("SinaWeibo".equals(platform.getName())) {//新浪微博
                    paramsToShare.setTitle(shopInfoEntity.getWzxx().getAreaName() + shopInfoEntity.getRealAddress());
                    paramsToShare.setText("租金:" + shopInfoEntity.getMonthlyRent() + "元/月\t\n商铺面积:" + shopInfoEntity.getWyxx().getBuildArea() + "㎡");
                    paramsToShare.setImageData(wxBitMap);
                    /*paramsToShare.setFilePath(ResourcesManager.getInstace(MobSDK.getContext()).getFilePath());*/
                    paramsToShare.setUrl("http://m.zpb.youpuchina.com/#/shopDetail?id=1&url=" + shopId);
                }
                if ("Wechat".equals(platform.getName())) {//微信
                    paramsToShare.setTitle(shopInfoEntity.getWzxx().getAreaName() + shopInfoEntity.getRealAddress());
                    paramsToShare.setUrl("http://m.zpb.youpuchina.com/#/shopDetail?id=1&url=" + shopId);
                    paramsToShare.setText("租金:" + shopInfoEntity.getMonthlyRent() + "元/月\t\n商铺面积:" + shopInfoEntity.getWyxx().getBuildArea() + "㎡");
                    paramsToShare.setImageData(wxBitMap);
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);

                }
                if ("WechatFavorite".equals(platform.getName())) {//收藏
                    paramsToShare.setTitle(shopInfoEntity.getWzxx().getAreaName() + shopInfoEntity.getRealAddress());
                    paramsToShare.setUrl("http://m.zpb.youpuchina.com/#/shopDetail?id=1&url=" + shopId);
                    paramsToShare.setText("租金:" + shopInfoEntity.getMonthlyRent() + "元/月\t\n商铺面积:" + shopInfoEntity.getWyxx().getBuildArea() + "㎡");
                    paramsToShare.setImageData(wxBitMap);
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);

                }
                if ("WechatMoments".equals(platform.getName())) {//朋友圈
                    paramsToShare.setTitle(shopInfoEntity.getWzxx().getAreaName() + shopInfoEntity.getRealAddress());
                    paramsToShare.setText("租金:" + shopInfoEntity.getMonthlyRent() + "元/月\t\n商铺面积:" + shopInfoEntity.getWyxx().getBuildArea() + "㎡");
                    paramsToShare.setImageData(wxBitMap);
                    paramsToShare.setUrl("http://m.zpb.youpuchina.com/#/shopDetail?id=1&url=" + shopId);
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
                }
                if ("QQ".equals(platform.getName())) {//QQ
                    paramsToShare.setTitle(shopInfoEntity.getWzxx().getAreaName() + shopInfoEntity.getRealAddress());
                    paramsToShare.setText("租金:" + shopInfoEntity.getMonthlyRent() + "元/月\t\n商铺面积:" + shopInfoEntity.getWyxx().getBuildArea() + "㎡");
                    paramsToShare.setTitleUrl("http://m.zpb.youpuchina.com/#/shopDetail?id=1&url=" + shopId);
                    paramsToShare.setImagePath(QQFilePath);
                }
              /*  if ("Facebook".equals(platform.getName())) {
                    //Facebook空间您自己写了
                    paramsToShare.setText("我是共用的参数,这几个平台都有text参数要求,提取出来啦");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                }*/
               /* if ("QZone".equals(platform.getName())) {
                    //QQ空间您自己写了
                }*/
                /*if ("Alipay".equals(platform.getName())) {
                    paramsToShare.setTitle("标题");
                    paramsToShare.setUrl("http://sharesdk.cn");
                    paramsToShare.setText("我是共用的参数,这几个平台都有text参数要求,提取出来啦");
                    *//*Bitmap imageData = BitmapFactory.decodeResource(getResources(), R.drawable.ssdk_logo);
                    paramsToShare.setImageData(imageData);*//*
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
                }*/
            }
        });
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                Log.d("ShareLogin", "onComplete ---->  分享成功");
                Toast.makeText(ShopDetailsActivity.this, "分享成功", Toast.LENGTH_SHORT).show();
                platform.getName();
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                Toast.makeText(ShopDetailsActivity.this, "分享失败", Toast.LENGTH_SHORT).show();
                Log.d("ShareLogin", "onError ---->  失败" + throwable.getStackTrace().toString());
                Log.d("ShareLogin", "onError ---->  失败" + throwable.getMessage());
            }

            @Override
            public void onCancel(Platform platform, int i) {
                Toast.makeText(ShopDetailsActivity.this, "分享取消", Toast.LENGTH_SHORT).show();
                Log.d("ShareLogin", "onCancel ---->  分享取消");
            }
        });

// 启动分享GUI
        oks.show(this);

    }

 

此博客作为笔记记录

posted @ 2018-04-24 18:34  丁先森  阅读(2204)  评论(0编辑  收藏  举报