文本
new
ShareAction(ShareActivity.this).withText("hello").withMedia(image).share();
图片
在使用ShareAction的时候,调用withMedia可以设置一个UMImage(图片分享),UMImage的构建有如下几种形式
UMImage image = new UMImage(ShareActivity.this, "imageurl");//网络图片UMImage image = new UMImage(ShareActivity.this, file);//本地文件UMImage image = new UMImage(ShareActivity.this, R.drawable.xxx);//资源文件UMImage image = new UMImage(ShareActivity.this, bitmap);//bitmap文件UMImage image = new UMImage(ShareActivity.this, byte[]);//字节流
推荐使用网络图片和资源文件的方式,平台兼容性更高。
对于部分平台,分享的图片需要设置缩略图,缩略图的设置规则为:
UMImage thumb = new UMImage(this, R.drawable.thumb);
image.setThumb(thumb);
用户设置的图片大小最好不要超过250k,缩略图不要超过18k,如果超过太多(最好不要分享1M以上的图片,压缩效率会很低),图片会被压缩。 用户可以设置压缩的方式:
image.compressStyle
= UMImage.CompressStyle.SCALE;//大小压缩,默认为大小压缩,适合普通很大的图image.compressStyle
= UMImage.CompressStyle.QUALITY;//质量压缩,适合长图的分享压缩格式设置image.compressFormat
= Bitmap.CompressFormat.PNG;//用户分享透明背景的图片可以设置这种方式,但是qq好友,微信朋友圈,不支持透明背景图片,会变成黑色
创建好UMImage之后调用分享即可,如下所示:
new
ShareAction(ShareActivity.this).withText("hello").withMedia(image).share();
2.3.3 链接
分享链接可以使用UMWeb进行分享:
UMWeb web = new UMWeb(Defaultcontent.url);
web.setTitle("This is music title");//标题
web.setThumb(thumb); //缩略图
web.setDescription("my description");//描述
然后调用将这个参数设置到ShareAction中:
new ShareAction(ShareActivity.this)
.withMedia(web)
.share();
2.3.4 视频
视频只能使用网络视频:
UMVideo video = new UMVideo(videourl);
video.setTitle("This is music title");//视频的标题
video.setThumb("http://www.umeng.com/images/pic/social/chart_1.png");//视频的缩略图
video.setDescription("my description");//视频的描述
建立好之后可以进行分享:
new ShareAction(ShareActivity.this).withText("hello").withMedia(video).share();
2.3.5 音乐
音乐只能使用网络音乐:
UMusic music = new UMusic(musicurl);//音乐的播放链接
music.setTitle("This is music title");//音乐的标题
music.setThumb("http://www.umeng.com/images/pic/social/chart_1.png");//音乐的缩略图
music.setDescription("my description");//音乐的描述
music.setmTargetUrl(Defaultcontent.url);//音乐的跳转链接
建立好之后可以进行分享:
new ShareAction(ShareActivity.this)
.withMedia(music)
.share();
特别说明:播放链接是指在微信qq分享音乐,是可以在当前聊天界面播放的,要求这个musicurl(播放链接)必须要以.mp3等音乐格式结尾,跳转链接是指点击linkcard之后进行跳转的链接。
2.3.6 GIF
目前只有微信好友分享支持Emoji表情,其他平台暂不支持
UMEmoji emoji = new UMEmoji(this,"http://img5.imgtn.bdimg.com/it/u=2749190246,3857616763&fm=21&gp=0.jpg");
emoji.setThumb(new UMImage(this, R.drawable.thumb));
new ShareAction(ShareActivity.this)
.withMedia(emoji)
.share();
2.3.7 微信小程序
目前只有微信好友支持小程序分享,朋友圈,收藏及其他平台暂不支持:
UMMin umMin = new UMMin(Defaultcontent.url);
umMin.setThumb(imagelocal);
umMin.setTitle(Defaultcontent.title);
umMin.setDescription(Defaultcontent.text);
umMin.setPath("pages/page10007/xxxxxx");
umMin.setUserName("xx_xxx");
new ShareAction(ShareDetailActivity.this)
.withMedia(umMin)
.setPlatform(share_media)
.setCallback(shareListener)
.share();
3. 用户资料基本信息解析如下
在返回的map中各个信息对应的key值如下
3.1 新浪微博:
用户id:uid
accesstoken: accessToken (6.2以前用access_token)
refreshtoken: (6.2以前用refresh_token)
过期时间:expiration (6.2以前用expires_in)
用户名:name(6.2以前用screen_name)
位置:location
头像:iconurl(6.2以前用profile_image_url)
性别:gender
关注数:followers_count
好友数:friends_count
3.2 qq:
name:name(6.2以前用screen_name)
用户id:uid
accesstoken: accessToken (6.2以前用access_token)
过期时间:expiration (6.2以前用expires_in)
性别:gender
头像:iconurl(6.2以前用profile_image_url)
是否黄钻:is_yellow_year_vip
黄钻等级:yellow_vip_level
城市:city
省份:province