概述
随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
StartActivity:
package com.home.testshare;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StartActivity extends Activity implements OnClickListener {
private Button authorizeBtn;
private Button shareBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
initWidget();
}
private void initWidget() {
authorizeBtn = (Button) findViewById(R.id.start_btn_authorize);
shareBtn = (Button) findViewById(R.id.start_btn_share);
authorizeBtn.setOnClickListener(this);
shareBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == authorizeBtn) {
Intent intent = new Intent(this, AuthorizeActivity.class);
startActivity(intent);
} else if (v == shareBtn) {
Intent intent = new Intent(this, ShareActivity.class);
startActivity(intent);
}
}
}
AuthorizeActivity:
package com.home.testshare;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.sharesdk.douban.Douban;
import cn.sharesdk.dropbox.Dropbox;
import cn.sharesdk.evernote.Evernote;
import cn.sharesdk.facebook.Facebook;
import cn.sharesdk.flickr.Flickr;
import cn.sharesdk.foursquare.FourSquare;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.instagram.Instagram;
import cn.sharesdk.kaixin.KaiXin;
import cn.sharesdk.linkedin.LinkedIn;
import cn.sharesdk.netease.microblog.NetEaseMicroBlog;
import cn.sharesdk.renren.Renren;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.sohu.microblog.SohuMicroBlog;
import cn.sharesdk.sohu.suishenkan.SohuSuishenkan;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.tencent.weibo.TencentWeibo;
import cn.sharesdk.tumblr.Tumblr;
import cn.sharesdk.twitter.Twitter;
import cn.sharesdk.vkontakte.VKontakte;
import cn.sharesdk.youdao.YouDao;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class AuthorizeActivity extends Activity implements OnItemClickListener,
PlatformActionListener, Callback {
private ListView listView;
private String[] names;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.authorize);
ShareSDK.initSDK(this);
handler = new Handler(this);
listView = (ListView) findViewById(R.id.authorize_lv);
listView.setOnItemClickListener(this);
initData();
}
@Override
protected void onDestroy() {
super.onDestroy();
ShareSDK.stopSDK(this);
}
/**
* 初始化ListView数据
*/
private void initData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
names = new String[] { SinaWeibo.NAME, TencentWeibo.NAME, QZone.NAME,
Renren.NAME, KaiXin.NAME, SohuMicroBlog.NAME,
NetEaseMicroBlog.NAME, Douban.NAME, Evernote.NAME, YouDao.NAME,
Facebook.NAME, Twitter.NAME, LinkedIn.NAME, Dropbox.NAME,
Flickr.NAME, FourSquare.NAME, Instagram.NAME,
SohuSuishenkan.NAME, Tumblr.NAME, VKontakte.NAME };
int[] imageIds = new int[] { R.drawable.logo_sinaweibo,
R.drawable.logo_tencentweibo, R.drawable.logo_qzone,
R.drawable.logo_renren, R.drawable.logo_kaixin,
R.drawable.logo_sohumicroblog,
R.drawable.logo_neteasemicroblog, R.drawable.logo_douban,
R.drawable.logo_evernote, R.drawable.logo_youdao,
R.drawable.logo_facebook, R.drawable.logo_twitter,
R.drawable.logo_linkedin, R.drawable.logo_dropbox,
R.drawable.logo_flickr, R.drawable.logo_foursquare,
R.drawable.logo_instagram, R.drawable.logo_sohusuishenkan,
R.drawable.logo_tumblr, R.drawable.logo_vkontakte };
for (int i = 0; i < names.length; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", names[i]);
map.put("image", imageIds[i]);
list.add(map);
}
MyAdapter adapter = new MyAdapter(this, list);
listView.setAdapter(adapter);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Platform plat = ShareSDK.getPlatform(this, names[arg2]);
plat.setPlatformActionListener(this);
plat.showUser(null);
}
@Override
public boolean handleMessage(Message msg) {
Platform plat = (Platform) msg.obj;
switch (msg.arg1) {
case 1: { // success
Toast.makeText(this, plat.getName() + "授权成功", Toast.LENGTH_SHORT)
.show();
}
break;
case 2: { // error
Toast.makeText(this, plat.getName() + "授权失败", Toast.LENGTH_SHORT)
.show();
return false;
}
case 3: { // cancel
Toast.makeText(this, plat.getName() + "授权取消", Toast.LENGTH_SHORT)
.show();
return false;
}
}
Intent intent = new Intent(AuthorizeActivity.this, MainActivity.class);
intent.putExtra("name", plat.getName());
startActivity(intent);
return false;
}
@Override
public void onCancel(Platform plat, int arg1) {
Message msg = new Message();
msg.arg1 = 3;
msg.obj = plat;
handler.sendMessage(msg);
}
@Override
public void onComplete(Platform plat, int arg1, HashMap<String, Object> arg2) {
Message msg = new Message();
msg.arg1 = 1;
msg.obj = plat;
handler.sendMessage(msg);
}
@Override
public void onError(Platform plat, int arg1, Throwable t) {
t.printStackTrace();
Message msg = new Message();
msg.arg1 = 2;
msg.obj = plat;
handler.sendMessage(msg);
}
}
ShareActivity:
package com.home.testshare;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.renren.Renren;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.tencent.weibo.TencentWeibo;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ShareActivity extends Activity implements OnClickListener {
private Button noUIBtn;
private Button hasUIBtn;
public static String TEST_IMAGE;
private Button QQZoneBtn;
private Button txweiboBtn;
private Button sinaBtn;
private Button renrenBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share);
ShareSDK.initSDK(this);
initWidget();
initImage();
}
private void initWidget() {
noUIBtn = (Button) findViewById(R.id.share_btn_all_noUI);
hasUIBtn = (Button) findViewById(R.id.share_btn_all_hasUI);
QQZoneBtn = (Button) findViewById(R.id.share_btn_Qzone);
txweiboBtn = (Button) findViewById(R.id.share_btn_txweibo);
sinaBtn = (Button) findViewById(R.id.share_btn_sinaweibo);
renrenBtn = (Button) findViewById(R.id.share_btn_renren);
noUIBtn.setOnClickListener(this);
hasUIBtn.setOnClickListener(this);
QQZoneBtn.setOnClickListener(this);
txweiboBtn.setOnClickListener(this);
sinaBtn.setOnClickListener(this);
renrenBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == noUIBtn) {
showShare(true, null);
} else if (v == hasUIBtn) {
showShare(false, null);
} else if (v == QQZoneBtn) {
showShare(false, QZone.NAME);
} else if (v == txweiboBtn) {
showShare(false, TencentWeibo.NAME);
} else if (v == sinaBtn) {
showShare(false, SinaWeibo.NAME);
} else if (v == renrenBtn) {
showShare(false, Renren.NAME);
}
}
private void showShare(boolean silent, String platform) {
final OnekeyShare oks = new OnekeyShare();
oks.setNotification(R.drawable.ic_launcher,
this.getString(R.string.app_name));
oks.setAddress("12345678901");
oks.setTitle(this.getString(R.string.evenote_title));
oks.setTitleUrl("http://sharesdk.cn");
oks.setText(this.getString(R.string.share_content));
oks.setImagePath(TEST_IMAGE);
oks.setImageUrl("http://img.appgo.cn/imgs/sharesdk/content/2013/07/25/1374723172663.jpg");
oks.setUrl("http://www.sharesdk.cn");
oks.setFilePath(TEST_IMAGE);
oks.setComment(this.getString(R.string.share));
oks.setSite(this.getString(R.string.app_name));
oks.setSiteUrl("http://sharesdk.cn");
oks.setVenueName("ShareSDK");
oks.setVenueDescription("This is a beautiful place!");
oks.setLatitude(23.056081f);
oks.setLongitude(113.385708f);
oks.setSilent(silent);
if (platform != null) {
oks.setPlatform(platform);
}
// 去除注释,可令编辑页面显示为Dialog模式
// oks.setDialogMode();
// 去除注释,在自动授权时可以禁用SSO方式
// oks.disableSSOWhenAuthorize();
// 去除注释,则快捷分享的操作结果将通过OneKeyShareCallback回调
// oks.setCallback(new OneKeyShareCallback());
// 去除注释,演示在九宫格添加自定义的图标
// Bitmap logo = BitmapFactory.decodeResource(getResources(),
// R.drawable.ic_launcher);
// String label = getString(R.string.app_name);
// OnClickListener listener = new OnClickListener() {
// public void onClick(View v) {
// String text = "Customer Logo -- ShareSDK "
// + ShareSDK.getSDKVersionName();
// Toast.makeText(ShareActivity.this, text, Toast.LENGTH_SHORT)
// .show();
// oks.finish();
// }
// };
// oks.setCustomerLogo(logo, label, listener);
oks.show(this);
}
private void initImage() {
try {
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())
&& Environment.getExternalStorageDirectory().exists()) {
File baseFile = new File(
Environment.getExternalStorageDirectory(), "share");
if (!baseFile.exists()) {
baseFile.mkdir();
}
TEST_IMAGE = baseFile.getAbsolutePath() + "/picture.png";
} else {
TEST_IMAGE = getApplication().getFilesDir().getAbsolutePath()
+ "/picture.png";
}
File file = new File(TEST_IMAGE);
if (!file.exists()) {
file.createNewFile();
Bitmap pic = BitmapFactory.decodeResource(getResources(),
R.drawable.picture);
FileOutputStream fos = new FileOutputStream(file);
pic.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
}
} catch (Throwable t) {
t.printStackTrace();
TEST_IMAGE = null;
}
}
class OneKeyShareCallback implements PlatformActionListener {
public void onComplete(Platform plat, int action,
HashMap<String, Object> res) {
System.out.println(res.toString());
// 在这里添加分享成功的处理代码
}
public void onError(Platform plat, int action, Throwable t) {
t.printStackTrace();
// 在这里添加分享失败的处理代码
}
public void onCancel(Platform plat, int action) {
// 在这里添加取消分享的处理代码
}
}
}
MainActivity:
package com.home.testshare;
import java.util.HashMap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
public class MainActivity extends Activity implements OnClickListener,
PlatformActionListener, Callback {
private Button getInfoBtn;
private Button logoutBtn;
private String platName;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initWidget();
platName = getIntent().getStringExtra("name");
handler = new Handler(this);
}
private void initWidget() {
getInfoBtn = (Button) findViewById(R.id.main_btn_getInfo);
logoutBtn = (Button) findViewById(R.id.main_btn_logout);
getInfoBtn.setOnClickListener(this);
logoutBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == getInfoBtn) {
if (platName == null || "".equals(platName)) {
Toast.makeText(this, "获取信息失败", Toast.LENGTH_SHORT).show();
return;
}
Platform plat = ShareSDK.getPlatform(this, platName);
plat.setPlatformActionListener(this);
plat.showUser(null);
} else if (v == logoutBtn) {
if (platName == null || "".equals(platName)) {
Toast.makeText(this, "注销失败", Toast.LENGTH_SHORT).show();
return;
}
Platform plat = ShareSDK.getPlatform(this, platName);
if (plat != null && plat.isValid()) {
plat.removeAccount();
finish();
}
}
}
public boolean handleMessage(Message msg) {
switch (msg.arg1) {
case 1: { // success
Intent intent = new Intent(MainActivity.this,
ShowInfoActivity.class);
intent.putExtra("data", String.valueOf(msg.obj));
startActivity(intent);
}
break;
case 2: {// error
Platform plat = (Platform) msg.obj;
Toast.makeText(this, plat.getName() + "授权失败", Toast.LENGTH_SHORT)
.show();
}
break;
case 3: {// cancel
Platform plat = (Platform) msg.obj;
Toast.makeText(this, plat.getName() + "授权取消", Toast.LENGTH_SHORT)
.show();
}
break;
}
return false;
}
@Override
public void onCancel(Platform plat, int arg1) {
Message msg = new Message();
msg.arg1 = 3;
msg.obj = plat;
handler.sendMessage(msg);
}
@Override
public void onComplete(Platform arg0, int arg1, HashMap<String, Object> res) {
Message msg = new Message();
msg.arg1 = 1;
JsonUtils ju = new JsonUtils();
String json = ju.fromHashMap(res);
msg.obj = ju.format(json);
handler.sendMessage(msg);
}
@Override
public void onError(Platform plat, int arg1, Throwable arg2) {
Message msg = new Message();
msg.arg1 = 2;
msg.obj = plat;
handler.sendMessage(msg);
}
}
ShowInfoActivity:
package com.home.testshare;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ShowInfoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_info);
TextView show = (TextView) findViewById(R.id.show_info_tv);
show.setText(getIntent().getStringExtra("data"));
}
}
MyAdapter:
package com.home.testshare;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter {
private Context context;
private List<Map<String, Object>> list;
public MyAdapter(Context context, List<Map<String, Object>> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return list.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int position, View arg1, ViewGroup arg2) {
View view = LayoutInflater.from(context).inflate(R.layout.listview_row,
null);
ImageView imageView = (ImageView) view
.findViewById(R.id.listview_row_iv);
TextView textView = (TextView) view.findViewById(R.id.listview_row_tv);
imageView.setBackgroundResource((Integer) list.get(position).get(
"image"));
textView.setText((String) list.get(position).get("name"));
return view;
}
}
JsonUtils:
package com.home.testshare;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class JsonUtils {
public HashMap<String, Object> fromJson(String jsonStr) {
try {
if (jsonStr.startsWith("[") && jsonStr.endsWith("]")) {
jsonStr = "{"fakelist":" + jsonStr + "}";
}
JSONObject json = new JSONObject(jsonStr);
return fromJson(json);
} catch (Throwable t) {
t.printStackTrace();
}
return new HashMap<String, Object>();
}
private HashMap<String, Object> fromJson(JSONObject json)
throws JSONException {
HashMap<String, Object> map = new HashMap<String, Object>();
@SuppressWarnings("unchecked")
Iterator<String> iKey = json.keys();
while (iKey.hasNext()) {
String key = iKey.next();
Object value = json.opt(key);
if (JSONObject.NULL.equals(value)) {
value = null;
}
if (value != null) {
if (value instanceof JSONObject) {
value = fromJson((JSONObject) value);
} else if (value instanceof JSONArray) {
value = fromJson((JSONArray) value);
}
map.put(key, value);
}
}
return map;
}
private ArrayList<Object> fromJson(JSONArray array) throws JSONException {
ArrayList<Object> list = new ArrayList<Object>();
for (int i = 0, size = array.length(); i < size; i++) {
Object value = array.opt(i);
if (value instanceof JSONObject) {
value = fromJson((JSONObject) value);
} else if (value instanceof JSONArray) {
value = fromJson((JSONArray) value);
}
list.add(value);
}
return list;
}
public String fromHashMap(HashMap<String, Object> map) {
try {
return getJSONObject(map).toString();
} catch (Throwable t) {
t.printStackTrace();
}
return "";
}
@SuppressWarnings("unchecked")
private JSONObject getJSONObject(HashMap<String, Object> map)
throws JSONException {
JSONObject json = new JSONObject();
for (Entry<String, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value instanceof HashMap<?, ?>) {
value = getJSONObject((HashMap<String, Object>) value);
} else if (value instanceof ArrayList<?>) {
value = getJSONArray((ArrayList<Object>) value);
}
json.put(entry.getKey(), value);
}
return json;
}
@SuppressWarnings("unchecked")
private JSONArray getJSONArray(ArrayList<Object> list) throws JSONException {
JSONArray array = new JSONArray();
for (Object value : list) {
if (value instanceof HashMap<?, ?>) {
value = getJSONObject((HashMap<String, Object>) value);
} else if (value instanceof ArrayList<?>) {
value = getJSONArray((ArrayList<Object>) value);
}
array.put(value);
}
return array;
}
public String format(String jsonStr) {
try {
return format("", fromJson(jsonStr));
} catch (Throwable t) {
t.printStackTrace();
}
return "";
}
@SuppressWarnings("unchecked")
private String format(String sepStr, HashMap<String, Object> map) {
StringBuffer sb = new StringBuffer();
sb.append("{n");
String mySepStr = sepStr + "t";
int i = 0;
for (Entry<String, Object> entry : map.entrySet()) {
if (i > 0) {
sb.append(",n");
}
sb.append(mySepStr).append('"').append(entry.getKey())
.append("":");
Object value = entry.getValue();
if (value instanceof HashMap<?, ?>) {
sb.append(format(mySepStr, (HashMap<String, Object>) value));
} else if (value instanceof ArrayList<?>) {
sb.append(format(mySepStr, (ArrayList<Object>) value));
} else if (value instanceof String) {
sb.append('"').append(value).append('"');
} else {
sb.append(value);
}
i++;
}
sb.append('n').append(sepStr).append('}');
return sb.toString();
}
@SuppressWarnings("unchecked")
private String format(String sepStr, ArrayList<Object> list) {
StringBuffer sb = new StringBuffer();
sb.append("[n");
String mySepStr = sepStr + "t";
int i = 0;
for (Object value : list) {
if (i > 0) {
sb.append(",n");
}
sb.append(mySepStr);
if (value instanceof HashMap<?, ?>) {
sb.append(format(mySepStr, (HashMap<String, Object>) value));
} else if (value instanceof ArrayList<?>) {
sb.append(format(mySepStr, (ArrayList<Object>) value));
} else if (value instanceof String) {
sb.append('"').append(value).append('"');
} else {
sb.append(value);
}
i++;
}
sb.append('n').append(sepStr).append(']');
return sb.toString();
}
}
assets里面的ShareSDK.xml:
<?xml version="1.0" encoding="utf-8"?>
<DevInfor>
<!--
说明:
1、表格中的第一项
<ShareSDK
AppKey="api20" />
是必须的,其中的AppKey是您在ShareSDK上注册的开发者帐号的AppKey
2、所有集成到您项目的平台都应该为其在表格中填写相对应的开发者信息,以新浪微博为例:
<SinaWeibo
Id="1"
SortId="1"
AppKey="568898243"
AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
RedirectUrl="http://www.sharesdk.cn"
Enable="true" />
其中的SortId是此平台在分享列表中的位置,由开发者自行定义,可以是任何整型数字,数值越大
越靠后AppKey、AppSecret和RedirectUrl是您在新浪微博上注册开发者信息和应用后得到的信息
Id是一个保留的识别符,整型,ShareSDK不使用此字段,供您在自己的项目中当作平台的识别符。
Enable字段表示此平台是否有效,布尔值,默认为true,如果Enable为false,即便平台的jar包
已经添加到应用中,平台实例依然不可获取。
各个平台注册应用信息的地址如下:
新浪微博 http://open.weibo.com
腾讯微博 http://dev.t.qq.com
QQ空间 http://connect.qq.com/intro/login/
微信好友 http://open.weixin.qq.com
Facebook https://developers.facebook.com
Twitter https://dev.twitter.com
人人网 http://dev.renren.com
开心网 http://open.kaixin001.com
搜狐微博 http://open.t.sohu.com
网易微博 http://open.t.163.com
豆瓣 http://developers.douban.com
有道云笔记 http://note.youdao.com/open/developguide.html#app
印象笔记 https://dev.evernote.com/
Linkedin https://www.linkedin.com/secure/developer?newapp=
FourSquare https://developer.foursquare.com/
搜狐随身看 https://open.sohu.com/
Flickr http://www.flickr.com/services/
Pinterest http://developers.pinterest.com/
Tumblr http://www.tumblr.com/developers
Dropbox https://www.dropbox.com/developers
Instagram http://instagram.com/developer#
VKontakte http://vk.com/dev
-->
<ShareSDK AppKey="androidv1101" />
<!-- 修改成你在sharesdk后台注册的应用的appkey" -->
<SinaWeibo
AppKey="568898243"
AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
Enable="true"
Id="1"
RedirectUrl="http://www.sharesdk.cn"
SortId="1" />
<TencentWeibo
AppKey="801307650"
AppSecret="ae36f4ee3946e1cbb98d6965b0b2ff5c"
Enable="true"
Id="2"
RedirectUri="http://sharesdk.cn"
SortId="2" />
<QZone
AppId="100371282"
AppKey="aed9b0303e3ed1e27bae87c33761161d"
Enable="true"
Id="3"
SortId="3" />
<!--
Wechat微信和WechatMoments微信朋友圈的appid是一样的;
注意:开发者不能用我们这两个平台的appid,否则分享不了
微信测试的时候,微信测试需要先签名打包出apk,
sample测试微信,要先签名打包,keystore在sample项目中,密码123456
-->
<Wechat
AppId="wx4868b35061f87885"
Enable="true"
Id="4"
SortId="4" />
<WechatMoments
AppId="wx4868b35061f87885"
Enable="true"
Id="5"
SortId="5" />
<WechatFavorite
AppId="wx4868b35061f87885"
Enable="true"
Id="6"
SortId="6" />
<QQ
AppId="100371282"
AppKey="aed9b0303e3ed1e27bae87c33761161d"
Enable="true"
Id="7"
SortId="7" />
<Facebook
ConsumerKey="107704292745179"
ConsumerSecret="38053202e1a5fe26c80c753071f0b573"
Enable="true"
Id="8"
SortId="8" />
<Twitter
CallbackUrl="http://www.sharesdk.cn"
ConsumerKey="mnTGqtXk0TYMXYTN7qUxg"
ConsumerSecret="ROkFqr8c3m1HXqS3rm3TJ0WkAJuwBOSaWhPbZ9Ojuc"
Enable="true"
Id="9"
SortId="9" />
<Renren
ApiKey="fc5b8aed373c4c27a05b712acba0f8c3"
AppId="226427"
Enable="true"
Id="10"
SecretKey="f29df781abdd4f49beca5a2194676ca4"
SortId="10" />
<KaiXin
AppKey="358443394194887cee81ff5890870c7c"
AppSecret="da32179d859c016169f66d90b6db2a23"
Enable="true"
Id="11"
RedirectUri="http://www.sharesdk.cn"
SortId="11" />
<Email
Enable="true"
Id="12"
SortId="12" />
<ShortMessage
Enable="true"
Id="13"
SortId="13" />
<SohuMicroBlog
ApiKey="SAfmTG1blxZY3HztESWx"
CallbackUrl="http://www.sharesdk.cn"
ConsumerKey="SAfmTG1blxZY3HztESWx"
ConsumerSecret="yfTZf)!rVwh*3dqQuVJVsUL37!F)!yS9S!Orcsij"
Enable="true"
Id="14"
SortId="14" />
<NetEaseMicroBlog
ConsumerKey="T5EI7BXe13vfyDuy"
ConsumerSecret="gZxwyNOvjFYpxwwlnuizHRRtBRZ2lV1j"
Enable="true"
Id="15"
RedirectUri="http://www.shareSDK.cn"
SortId="15" />
<Douban
ApiKey="02e2cbe5ca06de5908a863b15e149b0b"
Enable="true"
Id="16"
RedirectUri="http://www.sharesdk.cn"
Secret="9f1e7b4f71304f2f"
SortId="16" />
<YouDao
ConsumerKey="dcde25dca105bcc36884ed4534dab940"
ConsumerSecret="d98217b4020e7f1874263795f44838fe"
Enable="true"
HostType="product"
Id="17"
RedirectUri="http://www.sharesdk.cn"
SortId="17" />
<SohuSuishenkan
AppKey="e16680a815134504b746c86e08a19db0"
AppSecret="b8eec53707c3976efc91614dd16ef81c"
Enable="true"
Id="18"
RedirectUri="http://sharesdk.cn"
SortId="18" />
<!--
在中国大陆,印象笔记有两个服务器,一个是沙箱(sandbox),一个是生产服务器(china)。
一般你注册应用,它会先让你使用sandbox,当你完成测试以后,可以到
http://dev.yinxiang.com/support/上激活你的ConsumerKey,激活成功后,修改HostType
为china就好了。至于如果您申请的是国际版的印象笔记(Evernote),则其生产服务器类型为
“product”。
如果目标设备上已经安装了印象笔记客户端,ShareSDK允许应用调用本地API来完成分享,但
是需要将应用信息中的“ShareByAppClient”设置为true,此字段默认值为false。
-->
<Evernote
ConsumerKey="sharesdk-7807"
ConsumerSecret="d05bf86993836004"
Enable="true"
HostType="sandbox"
Id="19"
ShareByAppClient="true"
SortId="19" />
<LinkedIn
ApiKey="ejo5ibkye3vo"
Enable="true"
Id="20"
RedirectUrl="http://sharesdk.cn"
SecretKey="cC7B2jpxITqPLZ5M"
SortId="20" />
<GooglePlus
Enable="true"
Id="21"
SortId="21" />
<FourSquare
ClientID="G0ZI20FM30SJAJTX2RIBGD05QV1NE2KVIM2SPXML2XUJNXEU"
ClientSecret="3XHQNSMMHIFBYOLWEPONNV4DOTCDBQH0AEMVGCBG0MZ32XNU"
Enable="true"
Id="22"
RedirectUrl="http://www.sharesdk.cn"
SortId="22" />
<Pinterest
ClientId="1432928"
Enable="true"
Id="23"
SortId="23" />
<Flickr
ApiKey="33d833ee6b6fca49943363282dd313dd"
ApiSecret="3a2c5b42a8fbb8bb"
Enable="true"
Id="24"
RedirectUri="http://www.sharesdk.cn"
SortId="24" />
<Tumblr
CallbackUrl="http://sharesdk.cn"
Enable="true"
Id="25"
OAuthConsumerKey="2QUXqO9fcgGdtGG1FcvML6ZunIQzAEL8xY6hIaxdJnDti2DYwM"
SecretKey="3Rt0sPFj7u2g39mEVB3IBpOzKnM3JnTtxX2bao2JKk4VV1gtNo"
SortId="25" />
<Dropbox
AppKey="7janx53ilz11gbs"
AppSecret="c1hpx5fz6tzkm32"
Enable="true"
Id="26"
SortId="26" />
<VKontakte
ApplicationId="3921561"
Enable="true"
Id="27"
SortId="27" />
<Instagram
ClientId="ff68e3216b4f4f989121aa1c2962d058"
ClientSecret="1b2e82f110264869b3505c3fe34e31a1"
Enable="true"
Id="28"
RedirectUri="http://sharesdk.cn"
SortId="28" />
<Yixin
AppId="yx0d9a9f9088ea44d78680f3274da1765f"
Enable="true"
Id="29"
SortId="29" />
<!-- AppId="yx28eafabad0934f8d8d34a2a7238f53a0" -->
<YixinMoments
AppId="yx0d9a9f9088ea44d78680f3274da1765f"
Enable="true"
Id="30"
SortId="30" />
</DevInfor>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.home.testshare"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.home.testshare.StartActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.home.testshare.AuthorizeActivity" />
<activity android:name="com.home.testshare.MainActivity" />
<activity android:name="com.home.testshare.ShowInfoActivity" />
<activity android:name="com.home.testshare.ShareActivity" />
<!-- share SDK -->
<activity
android:name="cn.sharesdk.framework.ShareSDKUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" >
<!--
AuthorizeAdapter表示一个继承自cn.sharesdk.framework.authorize.AuthorizeAdapter
的类,这个类可以监听到页面的生命周期,也可以获取授权页面的各种UI控件。
开发者可以通过继承AuthorizeAdapter,重写其方法,并获取各种UI来自定义这个页面的行为。
-->
<meta-data
android:name="AuthorizeAdapter"
android:value="cn.sharesdk.demo.MyAdapter" />
<!--
Dropbox的SSO功能需要在此处添加一个对ACTION_VIEW事件的过滤器,其中的scheme是
“db-”前缀再开发者应用的加上appKey。如果此过滤器不设置,则不能完成SSO功能授权
-->
<intent-filter>
<data android:scheme="db-7janx53ilz11gbs" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
布局文件layout:
start.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/start_btn_authorize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="授权" />
<Button
android:id="@+id/start_btn_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享" />
</LinearLayout>
authorize.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/authorize_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
listview_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/listview_row_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="5dp" />
<TextView
android:id="@+id/listview_row_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:textSize="18sp" />
</LinearLayout>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/main_btn_getInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="获取信息" />
<Button
android:id="@+id/main_btn_logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注销登录" />
</LinearLayout>
share.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/share_btn_all_hasUI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享全部(有分享界面)" />
<Button
android:id="@+id/share_btn_all_noUI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享全部(无分享界面)" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="分享到指定平台(只列出部分)" />
<Button
android:layout_marginTop="10dp"
android:id="@+id/share_btn_Qzone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享到QQ空间" />
<Button
android:id="@+id/share_btn_txweibo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享到腾讯微博" />
<Button
android:id="@+id/share_btn_sinaweibo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享到新浪微博" />
<Button
android:id="@+id/share_btn_renren"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="分享到人人网" />
</LinearLayout>
show_info.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<TextView
android:id="@+id/show_info_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:autoLink="all"
android:textColor="#ff000000" />
</ScrollView>
</RelativeLayout>
values里面的strings:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="app_name">TestShare</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<integer name="app_version_code">27</integer>
<string name="app_version">2.3.2</string>
<string name="proj_name">ShareSDK</string>
<string name="more">更多</string>
<string name="sm_item_demo">接口</string>
<string name="sm_item_auth">授权</string>
<string name="sm_item_wechat">微信</string>
<string name="sm_item_yixin">易信</string>
<string name="sm_item_customer">自定义接口</string>
<string name="sm_item_fl_weibo">关注新浪微博</string>
<string name="sm_item_fl_tc">关注腾讯微博</string>
<string name="sm_item_visit_wechat">关注官方微信</string>
<string name="sm_item_visit_website">关注官方网站</string>
<string name="sm_item_about">Demo版本 Ver. %s</string>
<string name="plz_choose_wechat">请选择微信客户端完成操作</string>
<string name="get_token_format">获取%s的AccessToken</string>
<string name="get_user_info_format">获取%s授权用户资料</string>
<string name="get_other_info_format">获取%s其他用户资料</string>
<string name="share_to_format">分享到%s</string>
<string name="demo_share_all_gui">分享全部(有分享界面)</string>
<string name="demo_share_all">分享全部(无界面,直接分享)</string>
<string name="demo_get_access_token">获取AccessToken</string>
<string name="demo_get_my_info">获取授权用户资料</string>
<string name="demo_get_other_info">获取其他用户资料</string>
<string name="get_sina_friends_list">获取新浪微博关注列表</string>
<string name="get_tencent_friends_list">获取腾讯微博关注列表</string>
<string name="customer_douban">搜索用户</string>
<string name="customer_facebook">获取通知列表</string>
<string name="customer_nemb">获取推荐话题</string>
<string name="customer_renren">上传照片到用户的相册</string>
<string name="customer_sina">获取微博主页列表</string>
<string name="customer_qzone">发表日志到QQ空间</string>
<string name="customer_tencent">获取我的粉丝列表</string>
<string name="customer_twitter">获取主页列表</string>
<string name="customer_kaixin">获取可能认识的人</string>
<string name="customer_sohu">获取好友列表</string>
<string name="customer_youdao">获取笔记本列表</string>
<string name="customer_suishenkan">获取搜狐随身看书签列表</string>
<string name="not_yet_authorized">尚未授权</string>
<string name="share_content">ShareSDK for Android不仅集成简单、支持如QQ好友、微信、新浪微博、腾讯微博等所有社交平台,而且还有强大的统计分析管理后台,实时了解用户、信息流、回流率、传播效应等数据,详情见官网http://sharesdk.cn @ShareSDK</string>
<string name="share_content_short">ShareSDK不仅集成简单、支持如微信、新浪微博、腾讯微博等社交平台,而且还有强大的统计分析管理后台,实时了解用户、信息流、回流率、传播效应等数据,详情见官网http://sharesdk.cn @ShareSDK</string>
<string name="evenote_title">ShareSDK是一个神奇的SDK</string>
<string name="update">文字分享</string>
<string name="image_upload">图片分享(本地图片)</string>
<string name="image_upload_bitmap">图片分享(Bitmap对象)</string>
<string name="image_upload_url">图片分享(网络图片)</string>
<string name="emoji_upload">表情分享(本地图片)</string>
<string name="emoji_upload_url">表情分享(网络图片)</string>
<string name="emoji_upload_bm">表情分享(Bitmap对象)</string>
<string name="music_upload">音乐分享</string>
<string name="video_upload">视频分享</string>
<string name="webpage_upload">网页分享(本地图片)</string>
<string name="webpage_upload_bitmap">网页分享(Bitmap对象)</string>
<string name="webpage_upload_url">网页分享(网络图片)</string>
<string name="app_upload">应用分享(携带文件)</string>
<string name="app_upload_extinfo">应用分享(携带脚本)</string>
<string name="file_upload">文件分享</string>
<string name="share_to_wechat">微信好友</string>
<string name="share_to_moment">微信朋友圈</string>
<string name="share_to_favorite">微信收藏</string>
<string name="wechat_demo_title">微信分享Demo标题</string>
<string name="qzone_add_blog_sample">
<h1>QQ互联</h1>
<font color="red">轻松分享,</font>
<font color="green">快乐生活。</font>
<a href="http://connect.qq.com">详情请看。</a>
<img src="http://imgcache.qq.com/ptlogin/head/1_100.gif" />
</string>
<string name="wechat_client_is_not_installed_correctly">微信客户端未安装或版本太旧</string>
<string name="wechat_client_not_support_following_operation">微信客户端不支持第三方应用执行关注功能</string>
<string name="share_to_yixin">易信好友</string>
<string name="share_to_yixin_moment">易信朋友圈</string>
<string name="share_to_yixin_favorite">易信收藏</string>
<string name="yixin_demo_title">易信分享Demo标题</string>
<string name="receive_rewards">恭喜你得到%s个金币!</string>
<string name="buy_success">购买成功</string>
<string name="buy_failed">购买失败</string>
<string name="weibo_oauth_regiseter">应用授权</string>
<string name="website">http://www.shareSDK.cn</string>
<string name="weibo_upload_content">分享图片</string>
<string name="wechat_client_inavailable">目前您的微信版本过低或未安装微信,需要安装微信才能使用</string>
<string name="google_plus_client_inavailable">Google+ 版本过低或者没有安装,需要升级或安装Google+才能使用!</string>
<string name="qq_client_inavailable">QQ 版本过低或者没有安装,需要升级或安装QQ才能使用!</string>
<string name="pinterest_client_inavailable">Pinterest版本过低或者没有安装,需要升级或安装Pinterest才能使用!</string>
<string name="instagram_client_inavailable">Instagram版本过低或者没有安装,需要升级或安装Instagram才能使用!</string>
<string name="yixin_client_inavailable">目前您的易信版本过低或未安装易信,需要安装易信才能使用</string>
<string name="sinaweibo">新浪微博</string>
<string name="tencentweibo">腾讯微博</string>
<string name="qzone">QQ空间</string>
<string name="wechat">微信好友</string>
<string name="wechatmoments">微信朋友圈</string>
<string name="wechatfavorite">微信收藏</string>
<string name="facebook">Facebook</string>
<string name="twitter">Twitter</string>
<string name="renren">人人网</string>
<string name="kaixin">开心网</string>
<string name="email">邮件</string>
<string name="shortmessage">信息</string>
<string name="sohumicroblog">搜狐微博</string>
<string name="sohusuishenkan">搜狐随身看</string>
<string name="neteasemicroblog">网易微博</string>
<string name="douban">豆瓣</string>
<string name="youdao">有道云笔记</string>
<string name="evernote">印象笔记</string>
<string name="linkedin">Linked In</string>
<string name="googleplus">Google+</string>
<string name="foursquare">FourSquare</string>
<string name="qq">QQ</string>
<string name="pinterest">Pinterest</string>
<string name="flickr">Flickr</string>
<string name="tumblr">Tumblr</string>
<string name="dropbox">Dropbox</string>
<string name="vkontakte">VK</string>
<string name="instagram">Instagram</string>
<string name="yixin">易信</string>
<string name="yixinmoments">易信朋友圈</string>
<string name="share_to_qzone">分享到QQ空间</string>
<string name="incentive_title">分享有奖</string>
<string name="failed_to_start_incentive_page">无法打开“分享有奖页面”</string>
<string name="download_faield">下载失败</string>
<string name="cancel">取消</string>
<string name="finish">完成</string>
<string name="sharing">分享操作正在后台进行…</string>
<string name="share_to">分享到</string>
<string name="share">分享</string>
<string name="multi_share">图文分享</string>
<string name="share_completed">分享成功</string>
<string name="share_canceled">分享已取消</string>
<string name="select_one_plat_at_least">请选择一个目标平台</string>
<string name="list_friends">%s的朋友</string>
<string name="share_failed">分享失败</string>
<string name="pull_to_refresh">下拉刷新</string>
<string name="release_to_refresh">松开刷新</string>
<string name="refreshing">刷新中…</string>
</resources>
最后
以上就是无辜自行车为你收集整理的使用share SDK实现第三方授权登录、分享综合(2.x版本)的全部内容,希望文章能够帮你解决使用share SDK实现第三方授权登录、分享综合(2.x版本)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复