其他分享
首页 > 其他分享> > umeng(友盟)实现第三方登录和分享详解之分享,腾讯T2亲自讲解

umeng(友盟)实现第三方登录和分享详解之分享,腾讯T2亲自讲解

作者:互联网

ps:设置图片位置

UMImageMark umImageMark = new UMImageMark();

umImageMark.setGravity(Gravity.BOTTOM | Gravity.RIGHT);

umImageMark.setMarkBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.umsocial_defaultwatermark));

``

当然图片资源还有

UMImage image = new UMImage(ShareActivity.this, “imageurl”);//网络图片

UMImage image = new UMImage(ShareActivity.this, file);//本地文件

UMImage image

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

= new UMImage(ShareActivity.this, R.drawable.xxx);//资源文件

UMImage image = new UMImage(ShareActivity.this, bitmap);//bitmap文件

UMImage image = new UMImage(ShareActivity.this, byte[]);//字节流

new ShareAction(ShareDetailActivity.this).withText(Defaultcontent.text)

.withMedia(imagelocal)

.setPlatform(share_media)

.setCallback(shareListener).share();

4)图文加链接

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();

5)视频分享

视频只能使用网络视频:

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();

6)音乐分享

音乐只能使用网络音乐:

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();

7)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();

8)微信小程序

目前只有微信好友支持小程序分享,朋友圈,收藏及其他平台暂不支持:

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();

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));

9)分享文件

new ShareAction(ShareDetailActivity.this)

.withFile(file)

.withText(Defaultcontent.text)

.withSubject(Defaultcontent.title)

.setPlatform(share_media)

.setCallback(shareListener).share();

file = new File(this.getFilesDir()+“test.txt”);

if (!file.exists()){

try {

file.createNewFile();

} catch (IOException e) {

e.printStackTrace();

}

}

if (SocializeUtils.File2byte(file).length<=0){

String content = “U-share分享”;

byte[] contentInBytes = content.getBytes();

try {

FileOutputStream fop = new FileOutputStream(file);

fop.write(contentInBytes);

fop.flush();

fop.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

10)有面板的自定义面板

/增加自定义按钮的分享面板/

mShareAction = new ShareAction(ShareMenuActivity.this).setDisplayList(

SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.WEIXIN_FAVORITE,

SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,

SHARE_MEDIA.ALIPAY, SHARE_MEDIA.RENREN, SHARE_MEDIA.DOUBAN,

SHARE_MEDIA.SMS, SHARE_MEDIA.EMAIL, SHARE_MEDIA.YNOTE,

SHARE_MEDIA.EVERNOTE, SHARE_MEDIA.LAIWANG, SHARE_MEDIA.LAIWANG_DYNAMIC,

SHARE_MEDIA.LINKEDIN, SHARE_MEDIA.YIXIN, SHARE_MEDIA.YIXIN_CIRCLE,

SHARE_MEDIA.TENCENT, SHARE_MEDIA.FACEBOOK, SHARE_MEDIA.TWITTER,

SHARE_MEDIA.WHATSAPP, SHARE_MEDIA.GOOGLEPLUS, SHARE_MEDIA.LINE,

SHARE_MEDIA.INSTAGRAM, SHARE_MEDIA.KAKAO, SHARE_MEDIA.PINTEREST,

SHARE_MEDIA.POCKET, SHARE_MEDIA.TUMBLR, SHARE_MEDIA.FLICKR,

SHARE_MEDIA.FOURSQUARE, SHARE_MEDIA.MORE)

.addButton(“umeng_sharebutton_copy”, “umeng_sharebutton_copy”, “umeng_socialize_copy”, “umeng_socialize_copy”)

.addButton(“umeng_sharebutton_copyurl”, “umeng_sharebutton_copyurl”, “umeng_socialize_copyurl”, “umeng_socialize_copyurl”)

.setShareboardclickCallback(new ShareBoardlistener() {

@Override

public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {

if (snsPlatform.mShowWord.equals(“umeng_sharebutton_copy”)) {

Toast.makeText(ShareMenuActivity.this, “复制文本按钮”, Toast.LENGTH_LONG).show();

} else if (snsPlatform.mShowWord.equals(“umeng_sharebutton_copyurl”)) {

Toast.makeText(ShareMenuActivity.this, “复制链接按钮”, Toast.LENGTH_LONG).show();

}else if(share_media == SHARE_MEDIA.SMS) {

new ShareAction(ShareMenuActivity.this).withText(“来自分享面板标题”)

.setPlatform(share_media)

.setCallback(mShareListener)

.share();

}else

{

UMWeb web = new UMWeb(Defaultcontent.url);

web.setTitle(“来自分享面板标题”);

web.setDescription(“来自分享面板内容”);

web.setThumb(new UMImage(ShareMenuActivity.this, R.drawable.logo));

new ShareAction(ShareMenuActivity.this).withMedia(web)

.setPlatform(share_media)

.setCallback(mShareListener)

.share();

}

}

});

分享面板监听

private ShareBoardlistener shareBoardlistener = new ShareBoardlistener() {

@Override

public void onclick(SnsPlatform snsPlatform,SHARE_MEDIA share_media) {

if (share_media==null){

//根据key来区分自定义按钮的类型,并进行对应的操作

if (snsPlatform.mKeyword.equals(“umeng_sharebutton_custom”)){

Toast.makeText(ShareActivity.this,“add button success”,Toast.LENGTH_LONG).show();

}

}

else {//社交平台的分享行为

new ShareAction(ShareActivity.this)

.setPlatform(share_media)

.setCallback(umShareListener)

.withText(“多平台分享”)

.share();

}

}

};

3、分享都需要回调和监听

private UMShareListener shareListener = new UMShareListener() {

/**

*/

@Override

public void onStart(SHARE_MEDIA platform) {

}

/**

*/

@Override

public void onResult(SHARE_MEDIA platform) {

Toast.makeText(ShareDetailActivity.this,“成功了”,Toast.LENGTH_LONG).show();

}

/**

*/

@Override

public void one rror(SHARE_MEDIA platform, Throwable t) {

Toast.makeText(ShareDetailActivity.this,“失败”+t.getMessage(),Toast.LENGTH_LONG).show();

}

/**

*/

@Override

public void onCancel(SHARE_MEDIA platform) {

Toast.makeText(ShareDetailActivity.this,“取消了”,Toast.LENGTH_LONG).show();

}

};

还需要在分享的activity加入

标签:umeng,MEDIA,T2,SHARE,new,share,分享
来源: https://blog.csdn.net/m0_65638583/article/details/122134074