Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[展示] Andriod 分享功能心得 附源码

[复制链接]
909026364 发表于 2014-7-15 17:14:46 | 显示全部楼层 |阅读模式
本帖最后由 909026364 于 2014-7-15 17:17 编辑

最近在开发app,想要实现分享功能,之前没有实现过这个功能。上网查了很多资料,折腾了很久,最后不得已还是用了现成的组件。
很快就实现了。。。。

先上个效果图:




下面是我的集成过程:

首先,下载SDK

然后,提交应用申请key

第三步,在各大社交网站的开放平台申请账号并通过审核
将以上数据填写到,项目的asstes目录下youtui_sdk.xml文件中
先看看是怎么在类里调用的[mw_shl_code=java,true]package com.wgs.jiesuo;



import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import cn.bidaround.youtui.YouTui;
import cn.bidaround.youtui.YouTuiViewType;
import cn.bidaround.youtui.login.AuthListener;
import cn.bidaround.youtui.login.AuthLogin;
import cn.bidaround.youtui.login.AuthUserInfo;
import cn.bidaround.youtui.social.ShareData;

import com.wgs.jiesuo.LockPatternView.Cell;
import com.wgs.jiesuo.LockPatternView.DisplayMode;
import com.wgs.jiesuo.LockPatternView.OnPatternListener;

public class MainActivity extends Activity implements OnClickListener {
// private OnPatternListener onPatternListener;
private LockPatternView lockPatternView;
private LockPatternUtils lockPatternUtils;
private Button btn_set_pwd;
private Button btn_reset_pwd;
private Button btn_check_pwd;
private boolean opFLag = false;
private Button popupBt, listBt;
private View main_sina_imageview, main_qq_imageview,
main_tencentwb_imageview;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
YouTui.init(this);
initView();

}

void initView() {
ShareData shareData = ShareData.getInstance();
shareData.isAppShare = false;
shareData.setDescription("友推积分组件");
shareData.setTitle("友推分享");
shareData
.setText("通过友推积分组件,开发者几行代码就可以为应用添加分享送积分功能,并提供详尽的后台统计数据,除了本身具备的分享功能外,开发者也可将积分功能单独集成在已有分享组件的app上,快来试试吧?");
shareData.setTarget_url("http://youtui.mobi/");
shareData
.setImageUrl("http://cdnup.b0.upaiyun.com/media/image/default.png");
// shareData.setImagePath(Environment.getExternalStorageDirectory()+YoutuiConstants.FILE_SAVE_PATH+"demo.png");

popupBt = (Button) findViewById(R.id.popup_bt);
popupBt.setOnClickListener(this);

main_sina_imageview = findViewById(R.id.main_sina_imageview);
main_sina_imageview.setOnClickListener(this);
main_qq_imageview = findViewById(R.id.main_qq_imageview);
main_qq_imageview.setOnClickListener(this);
main_tencentwb_imageview = findViewById(R.id.main_tencentwb_imageview);
main_tencentwb_imageview.setOnClickListener(this);
lockPatternView = (LockPatternView) findViewById(R.id.lpv_lock);
btn_reset_pwd = (Button) findViewById(R.id.btn_reset_pwd);
btn_set_pwd = (Button) findViewById(R.id.btn_set_pwd);
btn_check_pwd = (Button) findViewById(R.id.btn_check_pwd);
btn_reset_pwd.setOnClickListener(this);
btn_set_pwd.setOnClickListener(this);
btn_check_pwd.setOnClickListener(this);
lockPatternUtils = new LockPatternUtils(this);
lockPatternView.setOnPatternListener(new OnPatternListener() {

public void onPatternStart() {
}

public void onPatternDetected(List<Cell> pattern) {
if (opFLag) {
int result = lockPatternUtils.checkPattern(pattern);
if (result != 1) {
if (result == 0) {
lockPatternView.setDisplayMode(DisplayMode.Wrong);
Toast.makeText(MainActivity.this, "密码错误",
Toast.LENGTH_LONG).show();
} else {
lockPatternView.clearPattern();
Toast.makeText(MainActivity.this, "请设置密码",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}

} else {
Toast.makeText(MainActivity.this, "密码正确",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}
} else {
lockPatternUtils.saveLockPattern(pattern);
Toast.makeText(MainActivity.this, "密码已经设置",
Toast.LENGTH_LONG).show();
lockPatternView.clearPattern();
}

}

public void onPatternCleared() {
}

public void onPatternCellAdded(List<Cell> pattern) {
}
});
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_reset_pwd:
lockPatternView.clearPattern();
lockPatternUtils.clearLock();
break;
case R.id.btn_check_pwd:
opFLag = true;
break;
case R.id.btn_set_pwd:
opFLag = false;
break;
case R.id.popup_bt:
YouTui.show(this, YouTuiViewType.BLACK_POPUP,false);
break;

case R.id.main_sina_imageview:
//新浪第三方登录
AuthLogin sinaAuth = new AuthLogin();
AuthListener sinaListener = new AuthListener() {

@Override
public void onAuthSucess(Activity arg0, AuthUserInfo userInfo) {
Log.i("sinaGender:", userInfo.getSinaGender());
Log.i("sinaName:", userInfo.getSinaName());
Log.i("sinaProfileImageUrl:", userInfo.getSinaProfileImageUrl());
Log.i("sinaScreenname:", userInfo.getSinaScreenname());
Log.i("sinaUid:", userInfo.getSinaUid());
}

@Override
public void onAuthFail(Activity arg0) {

}

@Override
public void onAuthCancel(Activity arg0) {

}
};
sinaAuth.sinaAuth(this, sinaListener);
break;
case R.id.main_qq_imageview:
/** qq第三方登录 */
AuthLogin qqLogin = new AuthLogin();

AuthListener qqListener = new AuthListener() {

@Override
public void onAuthSucess(Activity act, AuthUserInfo userInfo) {
Log.i("qqGender:", userInfo.getQqGender());
Log.i("qqImageUrl:", userInfo.getQqImageUrl());
Log.i("qqNickName:", userInfo.getQqNickName());
Log.i("qqOpenid:", userInfo.getQqOpenid());
}

@Override
public void onAuthFail(Activity act) {

}

@Override
public void onAuthCancel(Activity act) {

}
};

qqLogin.qqAuth(this, qqListener);
//qq第三方登录
break;
case R.id.main_tencentwb_imageview:

/** 腾讯微博第三方登录 */
AuthLogin tencentWbLogin = new AuthLogin();
AuthListener tencentWbListener = new AuthListener() {
@Override
public void onAuthSucess(Activity act, AuthUserInfo userInfo) {

Log.i("tencentWbName:", userInfo.getTencentWbName());
Log.i("tencentWbNick:", userInfo.getTencentWbNick());
Log.i("tencentWbOpenid:", userInfo.getTencentWbOpenid());
Log.i("tencentWbHead:", userInfo.getTencentWbHead());
}

@Override
public void onAuthFail(Activity act) {

}

@Override
public void onAuthCancel(Activity act) {

}
};

tencentWbLogin.tencentWbAuth(this, tencentWbListener);
//腾讯微博第三方登录
break;
}
}

protected void onDestroy() {
//调用
YouTui.release(this);
super.onDestroy();
}

}[/mw_shl_code]


记得把youtui-lib 这个文件导入到Eclipse开发工具中,在引用add进项目中,如图。


记得在清单配置好相应的信息,具体内容看源码。直接附上源码地址!

http://youtui.mobi/download/index.htm
欢迎大家交流分享方法哈~











本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
 楼主| 909026364 发表于 2014-7-16 11:10:55 | 显示全部楼层
这么好的东西~ 自己顶一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-11-17 23:54 , Processed in 0.038916 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表