共计 9382 个字符,预计需要花费 24 分钟才能阅读完成。
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);
新浪微博分享图文
留神: 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);
正文完