利用新版ShareSDK进行手动分享(自定义分享界面)

时间:2024-07-01 09:03:50

之前有用过Share SDK进行快捷分享,可是官方demo中的快捷分享的界面已经设置死了,而公司的产品又设计了自己的分享界面,这就需要我进行手动分享了。当前ShareSDK版本是2.5.4。

看了一堆官方的文档,终于写出来了,好了,不废话,进入主题。

之前没有用过ShareSDK分享过的朋友建议先看看官方的文档,不要火急火急的就像照搬官方的demo,

此为文档地址:: http://wiki.sharesdk.cn/Android_快速集成指南

此为官方demo下载地址:http://sharesdk.cn/Download

此为我整合之后的直接分享源码下载地址:http://download.****.net/detail/u012573920/7214405

基本的集成方法,官方的文档里已经有说了,我这里就不多说了,要问我具体地址?,好吧,我服了你了: http://wiki.sharesdk.cn/Android_快速集成指南,

各个分享平台的开发者账户和应用注册信息地址请看这里:

新浪微博                 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

当然,上面的直接地址是介绍快速集成的,我这里要介绍的是如何手动代码配置各个分享平台的信息和各个分享方法如何直接调接口完成。

官方demo中在assets目录下有一个ShareSDK.xml的配置文件,里面有一堆的配置信息,官方demo中有个方法使用来读取这些配置信息的,

而有时候我们不需要分享到这么多的平台,虽然官方demo中可以在ShareSDK.xml中设置各个平台的Enable="false",用于隐藏对应平台的分享按钮,

可这样实在不够清晰,我们开发这并不能很好的了解分享需要用到哪些代码,这一点,我想有过二次开发经验的朋友可以理解,

1  ...以下是官方demo里ShareSDK.xml文件中关于新浪微博的配置:

<SinaWeibo
                Id="1"  
                SortId="1"       //此平台在分享列表中的位置,由开发者自行定义,可以是任何整型数字,数值越大越靠后
                AppKey="568898243"
                AppSecret="38a4f8204cc784f81f9f0daaf31e02e3"
                RedirectUrl="http://www.sharesdk.cn"
                Enable="true" />

对于新浪微博,如果你需要图文分享,还必须在新浪公开平台申请一个接口权限,微博高级写入接口。此外,分享到新浪微博时,如果没有客户端则会直接分享出去不会弹出什么界面,这一点和其他应用的分享有差异们不用太纠结。有客户端时会弹出界面,可编辑。

AppKey、AppSecret和RedirectUrl是您在新浪微博上注册开发者信息和应用后得到的信息
    Id是一个保留的识别符,整型,ShareSDK不使用此字段,供您在自己的项目中当作平台的识别符。
    Enable字段表示此平台是否有效,布尔值,默认为true,如果Enable为false,即便平台的jar包
    已经添加到应用中,平台实例依然不可获取。

2...以下是我用代码配置的

HashMap<String, Object>
map = new HashMap<String, Object>();

map.put("AppKey", ShareConfig.APPKEY_SINA_WEIBO);
map.put("AppSecret", ShareConfig.APPSECRET_SINA_WEIBO);
map.put("RedirectUrl", ShareConfig.REDIRECTURL_SINA_WEIBO);
map.put("ShareByAppClient", ShareConfig.SHAREBYAPPCLIENT_SINA_WEIBO);
map.put("Enable", ShareConfig.ENABLE_SINA_WEIBO);
ShareSDK.setPlatformDevInfo(SinaWeibo.NAME, map);
ShareSDK.initSDK(this, ShareConfig.APPKEY);

cn.sharesdk.sina.weibo.SinaWeibo.ShareParams sp = new cn.sharesdk.sina.weibo.SinaWeibo.ShareParams();
sp.setShareType(Platform.SHARE_WEBPAGE);// 一定要设置分享属性
sp.setText(share_text + share_url);
sp.setImageUrl(share_image);
sp.setImagePath("");

Platform weibo = ShareSDK.getPlatform(this, SinaWeibo.NAME);
weibo.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
weibo.share(sp);

以上的具体该怎么配置请详细阅读这两个网址:1.http://wiki.sharesdk.cn/Android_分享到指定平台

2.http://wiki.sharesdk.cn/Android_不同平台分享内容的详细说明

一下是详细代码:

/**
* 分享界面
* SharedActivity.java
* Car273
*
* Created by 方鹏程 on 2014年4月11日
* Copyright (c) 1998-2014 273.cn. All rights reserved.
*/ package cn.car273.activity; import java.util.HashMap; import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.car273.R;
import cn.car273.app.ShareConfig;
import cn.car273.util.Utils;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.utils.UIHandler;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.system.text.ShortMessage;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments; import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader; public class SharedActivity extends Activity implements OnClickListener, PlatformActionListener,
Callback { public static String EXTRA_BIG_TITLE = "big_title"; public static String EXTRA_LITTLE_TITLE = "little_title"; public static String EXTRA_CAR_ID="id"; public static String EXTRA_CAR_IMAGE="image"; /** 分享的图片显示 */
private ImageView imageView_share_car; /** 分享的文字显示 */
private TextView textView_share_car; /** 退出分享按钮 */
private Button share_cancel; /** 分享到朋友圈按钮 */
private LinearLayout share_circleFriend; /** 分享到微信好友按钮 */
private LinearLayout share_wxFriend; /** 分享到QQ空间按钮 */
private LinearLayout share_qzone; /** 分享到QQ好友按钮 */
private LinearLayout share_qqFriend; /** 分享到短信按钮 */
private LinearLayout share_shortMessage; /** 分享到新浪微博按钮 */
private LinearLayout share_sinaWeibo; /** 分享的标题部分 */
private String share_title; /** 分享的文字内容部分 */
private String share_text; /** 分享的图片部分 */
private String share_image; /** 分享的网址部分 */
private String share_url; /** 分享无图标记 */
public static final String NOIMAGE = "noimage"; /** 记录当前分享点击状态 */
private boolean isClick = false; /** 短信分享按钮是否被点击 */
private boolean isSina = false; /** 新浪分享等待dilog */
private ProgressDialog dialog; /**
* 图片显示Options
*/
private DisplayImageOptions mOptions = null; /** 朋友圈注册数据 */
private HashMap<String, Object> map_circle; /** 微信好友注册数据 */
private HashMap<String, Object> map_wxFriend; /** QQ空间注册数据 */
private HashMap<String, Object> map_qzone; /** QQ好友注册数据 */
private HashMap<String, Object> map_qqFriend; /** 短信注册数据 */
private HashMap<String, Object> map_shortMessage; /** 新浪微博注册数据 */
private HashMap<String, Object> map_sina; /** 朋友圈分享对象 */
private Platform platform_circle; /** 微信好友分享对象 */
private Platform platform_wxFriend; /** QQ空间分享对象 */
private Platform platform_qzone; /** QQ好友分享对象 */
private Platform platform_qqFriend; /** 短信分享对象 */
private Platform platform_shortMessage; /** 新浪分享对象 */
private Platform platform_sina; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState); setContentView(R.layout.share_item_dialog);
// 组件初始化
initView();
// 数据初始化
initData();
// 组件添加监听
initAddOnClickListener();
} /**
* 定义一个函数将dp转换为像素
*
* @param context
* @param dp
* @return
*/
public int Dp2Px(float dp) {
final float scale = getResources().getDisplayMetrics().density;
return (int)(dp * scale / 2);
} /**
* @数据初始化
*/
private void initData() {
// 初始化sdk分享资源
ShareSDK.initSDK(this, ShareConfig.APPKEY);
initRegistInfo();
// 初始化要属相的内容
// share_title = getIntent().getStringExtra("share_title");
// share_text = getIntent().getStringExtra("share_text");
share_text = getIntent().getStringExtra(EXTRA_LITTLE_TITLE);
share_title = getIntent().getStringExtra(EXTRA_BIG_TITLE);
System.out.println("share_text---->"+share_text);
System.out.println("share_title---->"+share_title);
if (TextUtils.isEmpty(getIntent().getStringExtra(EXTRA_CAR_IMAGE))) {
// 没有默认图片吗,先用这张图片替代
share_image = "http://sta.273.com.cn/app/mbs/img/mobile_default.png";
} else {
share_image = imageUrl(getIntent().getStringExtra(EXTRA_CAR_IMAGE));
}
System.out.println("share_image---->"+share_image);
// http://m.273.cn/car/14923159.html?source=zzshare
share_url ="http://m.273.cn/car/"+getIntent().getStringExtra(EXTRA_CAR_ID)+".html?source=zzshare"; mOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.no_car)// 在ImageView加载过程中显示图片
.showImageForEmptyUri(R.drawable.no_car) // image连接地址为空时
.showImageOnFail(R.drawable.no_car) // image加载失败
.cacheInMemory(true)// 加载图片时会在内存中加载缓存
.cacheOnDisc(true).build();
ImageLoader.getInstance().displayImage(share_image, imageView_share_car, mOptions, null);
share_image = share_image.replace("110-110", "600-800");
} private String imageUrl(String imageUrl){ // int index = 0;
// if (!TextUtils.isEmpty(imageUrl)) {
// index = imageUrl.lastIndexOf(".");
// if (index != -1) {
// String extendName = imageUrl.substring(index);
// StringBuilder sb = new StringBuilder();
// sb.append(imageUrl.substring(0, index));
// sb.append("_");
// sb.append("_6_0_0").append(extendName);
// imageUrl = sb.toString();
// if (!imageUrl.startsWith("http://")) {
// imageUrl = RequestUrl.IMAGE_URL_API + imageUrl;
// }
// }
// } else {
// imageUrl = "";
// }
// return imageUrl; return Utils.formatImgUrl(imageUrl, 512, 0, false);
} /**
* 初始化各个平台注册信息
*/
private void initRegistInfo() {
// TODO Auto-generated method stub
map_circle = new HashMap<String, Object>();
map_wxFriend = new HashMap<String, Object>();
map_qzone = new HashMap<String, Object>();
map_qqFriend = new HashMap<String, Object>();
map_shortMessage = new HashMap<String, Object>();
map_sina = new HashMap<String, Object>(); map_circle.put("AppId", ShareConfig.APPID_CIRCLE_FRIEND);
map_circle.put("AppSecret", ShareConfig.APPSECRET_CIRCLE_FRIEND);
map_circle.put("Enable", ShareConfig.ENABLE_CIRCLE_FRIEND);
map_circle.put("BypassApproval", ShareConfig.BYPASSAPPROVAL_CIRCLE_FRIEND);
map_circle.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(WechatMoments.NAME, map_circle); map_wxFriend.put("AppId", ShareConfig.APPID_WXFRIEND);
map_wxFriend.put("Enable", ShareConfig.ENABLE_WXFRIEND);
map_wxFriend.put("BypassApproval", ShareConfig.BYPASSAPPROVAL_WXFRIEND);
map_wxFriend.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(Wechat.NAME, map_wxFriend); map_qzone.put("AppId", ShareConfig.APPID_QZONE);
map_qzone.put("AppKey", ShareConfig.APPKEY_QZONE);
map_qzone.put("ShareByAppClient", ShareConfig.SHAREBYAPPCLIENT_QZONE);
map_qzone.put("Enable", ShareConfig.ENABLE_QZONE);
map_qzone.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(QZone.NAME, map_qzone); map_qqFriend.put("AppId", ShareConfig.APPID_QQFRIEND);
map_qqFriend.put("AppKey", ShareConfig.APPKEY_QQFRIEND);
map_qqFriend.put("Enable", ShareConfig.ENABLE_QQFRIEND);
map_qqFriend.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(QQ.NAME, map_qqFriend); map_shortMessage.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(ShortMessage.NAME, map_shortMessage); map_sina.put("AppKey", ShareConfig.APPKEY_SINA_WEIBO);
map_sina.put("AppSecret", ShareConfig.APPSECRET_SINA_WEIBO);
map_sina.put("RedirectUrl", ShareConfig.REDIRECTURL_SINA_WEIBO);
map_sina.put("ShareByAppClient", ShareConfig.SHAREBYAPPCLIENT_SINA_WEIBO);//true
map_sina.put("Enable", ShareConfig.ENABLE_SINA_WEIBO);//true
map_sina.put("ShortLinkConversationEnable", "true");
ShareSDK.setPlatformDevInfo(SinaWeibo.NAME, map_sina); } /**
* @组件初始化
*/
private void initView() {
// imageView_share_car = (ImageView)findViewById(R.id.imageView_share_car);
// textView_share_car = (TextView)findViewById(R.id.textView_share_car);
share_cancel = (Button)findViewById(R.id.share_cancel);
share_cancel = (Button)findViewById(R.id.share_cancel);
share_circleFriend = (LinearLayout)findViewById(R.id.linearLayout_ciclefriend);
share_qqFriend = (LinearLayout)findViewById(R.id.LinearLayout_qqfriend);
share_qzone = (LinearLayout)findViewById(R.id.linearLayout_qzone);
share_shortMessage = (LinearLayout)findViewById(R.id.LinearLayout_shortmessage);
share_sinaWeibo = (LinearLayout)findViewById(R.id.LinearLayout_sinaweibo);
share_wxFriend = (LinearLayout)findViewById(R.id.linearLayout_weixin); dialog = new ProgressDialog(this);
dialog.setMessage(getResources().getString(R.string.loading_please_wait));
dialog.setCancelable(false);
} /**
* @组件添加监听
*/
private void initAddOnClickListener() {
share_cancel.setOnClickListener(this);
share_circleFriend.setOnClickListener(this);
share_qqFriend.setOnClickListener(this);
share_qzone.setOnClickListener(this);
share_shortMessage.setOnClickListener(this);
share_sinaWeibo.setOnClickListener(this);
share_wxFriend.setOnClickListener(this);
} /*
* (non-Javadoc)
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
@Override
public void onClick(View v) {
if (v.getId() == R.id.share_cancel) {
// 取消
SharedActivity.this.finish();
} else {
if (!isClick) {// 没点击才能点击
isClick = true;
switch (v.getId()) {
// 分享到微信朋友圈
case R.id.linearLayout_ciclefriend:
share_CircleFriend();
break;
// 分享到QQ空间
case R.id.linearLayout_qzone:
share_Qzone();
break;
// 分享到微信好友
case R.id.linearLayout_weixin:
share_WxFriend();
break;
// 分享到QQ好友
case R.id.LinearLayout_qqfriend:
share_QQFriend();
break;
// 分享到短信
case R.id.LinearLayout_shortmessage:
share_ShortMessage();
break;
// 分享到新浪微博
case R.id.LinearLayout_sinaweibo:
share_SinaWeibo();
break;
}
}
}
} /**
* 分享到朋友圈
*/
private void share_CircleFriend() {
if (!Utils.isHaveApp("com.tencent.mm", this)) {
Utils.showToast(this, "请先安装微信");
isClick = false;
return;
} platform_circle = ShareSDK.getPlatform(this, WechatMoments.NAME);
cn.sharesdk.wechat.moments.WechatMoments.ShareParams sp = new cn.sharesdk.wechat.moments.WechatMoments.ShareParams();
sp.setShareType(Platform.SHARE_WEBPAGE);// 一定要设置分享属性
sp.setTitle(share_title);
sp.setText(share_text);
sp.setImageUrl(share_image);
sp.setImagePath(null);
sp.setUrl(share_url); platform_circle.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_circle.share(sp);
} /**
* 分享到微信好友
*/
private void share_WxFriend() {
if (!Utils.isHaveApp("com.tencent.mm", this)) {
Utils.showToast(this, "请先安装微信");
isClick = false;
return;
} platform_wxFriend = ShareSDK.getPlatform(this, Wechat.NAME);
ShareParams sp = new ShareParams();
sp.setShareType(Platform.SHARE_WEBPAGE);// 一定要设置分享属性
sp.setTitle(share_title);
sp.setText(share_text);
sp.setUrl(share_url);
sp.setImageData(null);
sp.setImageUrl(share_image);
sp.setImagePath(null); platform_wxFriend.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_wxFriend.share(sp);
} /**
* 分享到QQ空间
*/
private void share_Qzone() {
platform_qzone = ShareSDK.getPlatform(this, QZone.NAME);
cn.sharesdk.tencent.qzone.QZone.ShareParams sp = new cn.sharesdk.tencent.qzone.QZone.ShareParams();
sp.setTitle(share_title);
sp.setText(share_text);
sp.setTitleUrl(share_url);
sp.setImageUrl(share_image);// imageUrl存在的时候,原来的imagePath将被忽略
sp.setSite("273二手车");
sp.setSiteUrl(share_url); platform_qzone.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_qzone.share(sp);
} /**
* 分享到QQ好友
*/
private void share_QQFriend() {
platform_qqFriend = ShareSDK.getPlatform(this, QQ.NAME);
cn.sharesdk.tencent.qq.QQ.ShareParams sp = new cn.sharesdk.tencent.qq.QQ.ShareParams();
sp.setShareType(Platform.SHARE_WEBPAGE);// 一定要设置分享属性
sp.setTitle(share_title);
sp.setTitleUrl(share_url);
sp.setText(share_text);
sp.setImageUrl(share_image);
sp.setImagePath(null); platform_qqFriend.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_qqFriend.share(sp);
} /**
* 分享到短信
*/
private void share_ShortMessage() {
platform_shortMessage = ShareSDK.getPlatform(this, ShortMessage.NAME);
cn.sharesdk.system.text.ShortMessage.ShareParams sp = new cn.sharesdk.system.text.ShortMessage.ShareParams();
sp.setAddress("");
sp.setText(share_text + share_url);
// platform_shortMessage.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_shortMessage.share(sp);
} /**
* 分享到新浪微博
*/
private void share_SinaWeibo() {
platform_sina = ShareSDK.getPlatform(SinaWeibo.NAME);
System.out.println("platform_sina.isValid()----"+platform_sina.isValid());
if (!platform_sina.isValid()) {// 如果有新浪微博客户端,每次都可以重新选择或添加分享账号
platform_sina.removeAccount();
} cn.sharesdk.sina.weibo.SinaWeibo.ShareParams sp = new cn.sharesdk.sina.weibo.SinaWeibo.ShareParams();
sp.setShareType(Platform.SHARE_WEBPAGE);
sp.setTitle(share_title);
sp.setText(share_text + share_url);
sp.setUrl(share_url);
sp.setImageUrl(share_image);
sp.setImagePath(null);
platform_sina.setPlatformActionListener(this); // 设置分享事件回调
// 执行图文分享
platform_sina.share(sp);
isSina = true;
dialog.show();
//一键快分享
// OnekeyShare oks = new OnekeyShare();
// //关闭sso授权
// oks.disableSSOWhenAuthorize();
//
// // 分享时Notification的图标和文字
// 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); } /*
* (non-Javadoc)
* @see android.app.Activity#onDestroy()
*/
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
// 释放资源空间
ShareSDK.stopSDK(this.getBaseContext());
super.onDestroy();
} public void onComplete(Platform plat, int action, HashMap<String, Object> res) { // 如果是通过微博客户端进行分享,则直接结束此页面
if (isSina) {
dialog.dismiss();
}
System.out.println("plat.getName()--->"+plat.getName()+" :"+SinaWeibo.NAME);
if (plat.getName().equals(SinaWeibo.NAME) && !platform_sina.isValid()) {
finish();
} else {
Message msg = new Message();
msg.arg1 = 1;
msg.arg2 = action;
msg.obj = plat;
UIHandler.sendMessage(msg, this);
}
} public void onCancel(Platform plat, int action) { if (isSina) {
dialog.dismiss();
}
isSina = false;
Message msg = new Message();
msg.arg1 = 3;
msg.arg2 = action;
msg.obj = plat;
UIHandler.sendMessage(msg, this);
} public void onError(Platform plat, int action, Throwable t) { Message msg = new Message();
msg.arg1 = 2;
msg.arg2 = action;
msg.obj = plat;
UIHandler.sendMessage(msg, this);
} public boolean handleMessage(Message msg) {
isClick = false;// 恢复未点击状态
switch (msg.arg1) {
// 1代表分享成功,2代表分享失败,3代表分享取消
case 1:
// 成功
Utils.showToast(this.getBaseContext(), "分享成功");
if (isSina) {
isSina = false;
SharedActivity.this.finish();
}
break;
case 2:
Utils.showToast(this.getBaseContext(), "分享失败");
// 失败
if (isSina) {
isSina = false;
SharedActivity.this.finish();
}
break; }
return false;
} @Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if (!isSina) {
finish();
}
} }

配置清单类

/**
* ShareConfig.java
* Car273
*
* @todo 分享模块的配置文件
* Created by ws on 2014年12月1日
* Copyright (c) 1998-2014 273.cn. All rights reserved.
*/ package cn.car273.app; /**
* @author Administrator
*
*/
public class ShareConfig { /** 此字段是在ShareSDK注册的应用所对应的appkey */
public static final String APPKEY ="45f6fcf2ec30"; /** 朋友圈 */
public static final String APPID_CIRCLE_FRIEND = "wxe4dccf34623d57f2";
public static final String APPSECRET_CIRCLE_FRIEND = "4ca9f03a72240a641c06a34525657829";
public static final String BYPASSAPPROVAL_CIRCLE_FRIEND = "fasle";
public static final String ENABLE_CIRCLE_FRIEND = "true"; /** 微信好友 */
public static final String APPID_WXFRIEND = "wxe4dccf34623d57f2";
public static final String APPSECRET_WXFRIEND = "4ca9f03a72240a641c06a34525657829";
public static final String BYPASSAPPROVAL_WXFRIEND = "false";
public static final String ENABLE_WXFRIEND = "true"; /** QQ空间 */
public static final String APPID_QZONE = "1150016865";
public static final String APPKEY_QZONE = "5f8e952b14022fa6d759e8ee06019cc2";
public static final String BYPASSAPPROVAL_QZONE = "false";
public static final String SHAREBYAPPCLIENT_QZONE = "true";
public static final String ENABLE_QZONE = "true"; /** QQ好友 */
public static final String APPID_QQFRIEND = "1150016865";
public static final String APPKEY_QQFRIEND = "5f8e952b14022fa6d759e8ee06019cc2";
public static final String BYPASSAPPROVAL_QQFRIEND = "false";
public static final String ENABLE_QQFRIEND = "true"; /** 短信 */ /** 新浪微博 */
public static final String APPKEY_SINA_WEIBO = "832671359";
public static final String APPSECRET_SINA_WEIBO = "8979588c843ff3c7c3e42e201bbcf90a";
public static final String REDIRECTURL_SINA_WEIBO = "http://www.273.cn";
public static final String BYPASSAPPROVAL_SINA_WEIBO = "false";
public static final String ENABLE_SINA_WEIBO = "true";
/**
* 设置了ShareByAppClient为true以后,ShareSDK会使用新浪微博的客户端来分享,
* 支持传递图文进行分享,支持回流统计,但是不支持分享结果回调,也就是说,微博客户端被打开,即当作分享成功。
*/
public static final String SHAREBYAPPCLIENT_SINA_WEIBO = "true"; }

清单文件中需要加入配置信息

     <!-- share -->

        <activity
android:name="cn.car273.activity.SharedActivity"
android:screenOrientation="portrait"
android:theme="@style/MyDialogStyleBottom" />
<!-- 分享相关的页面(ShareSDK需要调用到的) -->
<activity
android:name="cn.sharesdk.framework.ShareSDKUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" >
<intent-filter>
<data android:scheme="tencent100371282" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity> <!-- 微信分享回调 -->
<activity
android:name="cn.car273.wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

针对分享到微信,有一个回调类必须到项目中去,而是还必须添加到包名的直属目录下建立wxapi包,再放入回调类,不然拿不到回调!

如果按照这些做下来之后还有问题的话,请参考这里:http://wiki.sharesdk.cn/Android_常见问题,

至于怎么定义分享界面,请查看源码

PS:详细各位在仔细阅读以上信息之后有了一个大概了解了;想要源码的话,请下载http://download.****.net/detail/u012573920/7214405