ShareSDK|ShareSDK Android端主流平台分享示例

ShareSDK可以调用getPlatform接口设置要分享的平台,下面是分享示例:
微信分享示例(好友、朋友圈、收藏)
微信分享文本

Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_TEXT); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); platform.share(shareParams);

微信分享图片 注意: imageUrl(”网络图片链接”)、imagePath(“/sdcard/abc.jpg”)、imageData(bitmap)是三选一,同时Android11及之后的版本,微信分享图片不支持用imageData(bitmap)接口设置参数;
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_IMAGE); //分享网络图片 shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") //分享本地图片 //shareParams.setImagePath("本地图片的路径"); //分享bitmap图片 //shareParams.setImageData(bitmap); platform.share(shareParams);

微信分享音乐
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_MUSIC); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") shareParams.setMusicUrl( "http://music.baidu.com/song/546920050?pst=sug"); shareParams.setUrl("http://music.baidu.com/song/546920050?pst=su"); platform.share(shareParams);

微信分享视频
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_VIDEO); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") shareParams.setUrl("http://f1.webshare.mob.com/dvideo/demovideos.mp4"); platform.share(shareParams);

微信分享网页
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_WEBPAGE); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") shareParams.setUrl("https://www.mob.com/"); platform.share(shareParams);

微信分享文件
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_FILE); shareParams.setTitle("测试分享的标题"); shareParams.setFilePath("/storage/emulated/0/Android/data/cn.sharesdk.demo/files/text.txt"); //文件本地路径 platform.share(shareParams);

微信分享小程序 注意:只有微信好友支持分享小程序
Platform platform = ShareSDK.getPlatform(Wechat.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); //分享卡片形式小程序 shareParams.setShareType(Platform.SHARE_WXMINIPROGRAM); //直接打开微信小程序 //shareParams.setShareType(Platform.OPEN_WXMINIPROGRAM); shareParams.setText("测试文本"); shareParams.setTitle("测试分享的标题"); shareParams.setUrl("http://sharesdk.cn"); shareParams.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png"); //小程序状态:0-正式,1-开发,2-体验 shareParams.setWxMiniProgramType(0); //微信小程序多选,默认只能分享一个微信好友,设置false后可以分享多个 shareParams.setWxWithShareTicket(false); //分享的小程序页面路径,如不需要指定,请填主页路径(必填) shareParams.setWxPath("pages/index/index"); shareParams.setWxUserName("gh_52568203455c"); platform.share(shareParams);

新浪微博分享示例
新浪微博分享文字
Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); platform.share(shareParams);

新浪微博分享图文 【ShareSDK|ShareSDK Android端主流平台分享示例】注意: imageUrl(”网络图片链接”)、imagePath(“/sdcard/abc.jpg”)、imageData(bitmap)是三选一
Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); //分享网络图片 shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") //分享本地图片 //shareParams.setImagePath("本地图片的路径"); //分享bitmap图片 //shareParams.setImageData(bitmap); platform.share(shareParams);

新浪微博分享本地视频
Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); //视频文件本地路径 shareParams.setFilePath("/sdcard/video.MP4"); platform.share(shareParams);

QQ分享示例
QQ分享图片 注意:imageUrl(”网络图片链接”)、imagePath(“/sdcard/abc.jpg”)是二选一,同时QQ不支持分享bitmap图片
Platform platform = ShareSDK.getPlatform(QQ.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); //分享网络图片 shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") //分享本地图片 //shareParams.setImagePath("本地图片的路径"); platform.share(shareParams);

QQ分享网页
Platform platform = ShareSDK.getPlatform(QQ.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") //网页链接 shareParams.setTitleUrl("https://www.mob.com/"); platform.share(shareParams);

QQ分享音频
Platform platform = ShareSDK.getPlatform(QQ.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setTitle("测试分享的标题"); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg") shareParams.setTitleUrl("https://www.mob.com/"); //网页链接 shareParams.setMusicUrl( "http://music.baidu.com/song/546920050?pst=sug"); //音乐链接 platform.share(shareParams);

QQ分享小程序
Platform platform = ShareSDK.getPlatform(QQ.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("QQ小程序"); shareParams.setTitle("QQ互联"); shareParams.setTitleUrl("http://www.qq.com/"); shareParams.setImageUrl("http://www.3wyu.com/wpcontent/uploads/6e0eaf15gy1fvr5tnm2dfj20f108gtad.jpg"); shareParams.setShareType(Platform.QQ_MINI_PROGRAM); //分享小程序appid shareParams.setQQMiniProgramAppid("1109762672"); //分享的小程序页面路径,如不需要指定,请填主页路径(必填) shareParams.setQQMiniProgramPath("pages/index/index"); //3表示正式版,1表示体验版(可选) //shareParams.setQQMiniProgramType(""); platform.share(shareParams);

QQ空间分享示例 注意:必须需要QQ客户端才可以分享, site是分享此内容的网站名称,仅在QQ空间使用;siteUrl是分享此内容的网站地址,仅在QQ空间使用;
QQ空间分享视频
Platform platform = ShareSDK.getPlatform(QZone.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_VIDEO); //视频文件本地路径 shareParams.setFilePath("/sdcard/video.MP4"); platform.share(shareParams);

QQ空间分享文本
Platform platform = ShareSDK.getPlatform(QZone.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setTitle("测试分享的标题"); //网页链接 shareParams.setTitleUrl("https://www.mob.com/"); shareParams.setText("测试文本"); shareParams.setSite("测试文本"); shareParams.setSiteUrl("https://www.mob.com/"); platform.share(shareParams);

QQ空间分享说说
Platform platform = ShareSDK.getPlatform(QZone.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg"); shareParams.setSite("测试文本"); shareParams.setSiteUrl("https://www.mob.com/"); platform.share(shareParams);

QQ空间分享图文
Platform platform = ShareSDK.getPlatform(QZone.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setTitle("测试分享的标题"); shareParams.setTitleUrl("https://www.mob.com/"); shareParams.setText("测试文本"); //本地图片路径 shareParams.setImagePath("/storage/emulated/0/DCIM/Camera/IMG_20191001_113538.jpg"); shareParams.setSite("测试文本"); shareParams.setSiteUrl("https://www.mob.com/"); platform.share(shareParams);

Facebook分享示例
Facebook分享网页
Platform platform = ShareSDK.getPlatform(Facebook.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setQuote("测试web引文分享"); shareParams.setUrl("https://www.mob.com/"); platform.share(shareParams);

Facebook分享图片
Platform platform = ShareSDK.getPlatform(Facebook.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setHashtag("测试话题分享"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg"); platform.share(shareParams);

Facebook分享视频
Platform platform = ShareSDK.getPlatform(Facebook.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); //视频文件本地路径 shareParams.setFilePath("/sdcard/video.MP4"); platform.share(shareParams);

Facebook分享多图
Platform platform = ShareSDK.getPlatform(Facebook.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); //图片数组 shareParams.setImageArray(AVATARS); platform.share(shareParams);

Twitter分享示例
Twitter分享文本
Platform platform = ShareSDK.getPlatform(Twitter.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); platform.share(shareParams);

Twitter分享图文
Platform platform = ShareSDK.getPlatform(Twitter.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg"); platform.share(shareParams);

Twitter分享视频
Platform platform = ShareSDK.getPlatform(Twitter.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_VIDEO); //视频文件本地路径 shareParams.setFilePath("/sdcard/video.MP4"); platform.share(shareParams);

Instagram分享示例
Instagram分享图片
Platform platform = ShareSDK.getPlatform(Twitter.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); //文本不显示 shareParams.setText("测试文本"); shareParams.setImageUrl("https://img1.2345.com/duoteimg/qqTxImg/2012/04/09/13339485237265.jpg"); platform.share(shareParams);

Instagram分享图片
Platform platform = ShareSDK.getPlatform(Twitter.NAME); Platform.ShareParams shareParams = new Platform.ShareParams(); shareParams.setShareType(Platform.SHARE_VIDEO); //文本不显示 shareParams.setText("测试文本"); //视频文件本地路径 shareParams.setFilePath("/sdcard/video.MP4"); platform.share(shareParams);

    推荐阅读