使用shareSDK 进行分享和授权登录
2016-07-01 21:24
253 查看
授权登录: http://wiki.mob.com/%e6%8e%a5%e5%8f%a3%e8%b0%83%e7%94%a8%e5%8e%9f%e5%88%99/
一键分享:http://wiki.mob.com/Android_%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/
public class MainActivity extends AppCompatActivity {
// 分享时Notification的图标和文字 2.5.9以后的版本不调用此方法
//oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
// title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
oks.setTitle(getString(R.string.share));
// titleUrl是标题的网络链接,仅在人人网和QQ空间使用
oks.setTitleUrl(“http://sharesdk.cn“);
// text是分享文本,所有平台都需要这个字段
oks.setText(“我是分享文本”);
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
//oks.setImagePath(“/sdcard/test.jpg”);//确保SDcard下面存在此张图片
// url仅在微信(包括好友和朋友圈)中使用
oks.setUrl(“http://sharesdk.cn“);
// comment是我对这条分享的评论,仅在人人网和QQ空间使用
oks.setComment(“我是测试评论文本”);
// site是分享此内容的网站名称,仅在QQ空间使用
oks.setSite(getString(R.string.app_name));
// siteUrl是分享此内容的网站地址,仅在QQ空间使用
oks.setSiteUrl(“http://sharesdk.cn“);
// 启动分享GUI
oks.show(this);
}
}
一键分享:http://wiki.mob.com/Android_%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97/
public class MainActivity extends AppCompatActivity {
private OnekeyShare oks; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ShareSDK.initSDK(this); oks = new OnekeyShare(); } public void share(View view) { showShare(); } private void showShare() { //关闭sso授权 oks.disableSSOWhenAuthorize();
// 分享时Notification的图标和文字 2.5.9以后的版本不调用此方法
//oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
// title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
oks.setTitle(getString(R.string.share));
// titleUrl是标题的网络链接,仅在人人网和QQ空间使用
oks.setTitleUrl(“http://sharesdk.cn“);
// text是分享文本,所有平台都需要这个字段
oks.setText(“我是分享文本”);
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
//oks.setImagePath(“/sdcard/test.jpg”);//确保SDcard下面存在此张图片
// url仅在微信(包括好友和朋友圈)中使用
oks.setUrl(“http://sharesdk.cn“);
// comment是我对这条分享的评论,仅在人人网和QQ空间使用
oks.setComment(“我是测试评论文本”);
// site是分享此内容的网站名称,仅在QQ空间使用
oks.setSite(getString(R.string.app_name));
// siteUrl是分享此内容的网站地址,仅在QQ空间使用
oks.setSiteUrl(“http://sharesdk.cn“);
// 启动分享GUI
oks.show(this);
}
public void login(View view) { //使用sharesdk进行授权登录获取到用户资料 final Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME); if(!weibo.isValid()){ weibo.setPlatformActionListener(new PlatformActionListener() { @Override public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) { String token = weibo.getDb().getToken(); System.out.println("========token========"+token); // 操作成功的处理代码 } @Override public void onError(Platform platform, int i, Throwable throwable) { // 操作失败的处理代码 } @Override public void onCancel(Platform platform, int i) { // 操作取消的处理代码 } }); }else{ String nickname = weibo.getDb().get("nickname"); String icon = weibo.getDb().get("icon"); System.out.println("=====nickname======="+nickname); } }
}
相关文章推荐
- latex sty文件缺失问题
- [Leetcode]136. Single Number
- 【一天一道LeetCode】#113. Path Sum II
- allegro 有找到cmlib.dll,因此这个应用程序未能启动
- 最长回文子串
- 《机器学习》周志华第四章笔记
- matlplotlib figure imshow
- 地理名词、概念的解释
- 一些思路
- 【Matplotlib】 移动spines
- waypoints的使用
- 几种后端开发技术的选型调研
- [华为OJ] 数据分类处理
- Cannot complete the install because one or more required items could not be found.
- HDU 4901 The Romantic Hero
- C++: Virtual Table and Shared Memory
- 7.4将一个二维数组行和列元素互换,存到另一个二维数组中。
- 走遍世界 —— 南亚三大半岛
- CrackingtheCodeInterview之数组与字符串
- 编程之美2.16求数组中最长递增子序列Java版