社交分享组件有很多 介绍一下sharesdk 的使用
官网:http://sharesdk.cn/
1、先上效果图

2、主要代码:
- public class TestShare extends Activity {
-
- private RelativeLayout sina;
- private RelativeLayout sms;
- private RelativeLayout qq;
- private RelativeLayout chat;
- private TextView invite_code;
-
- private Context context;
- private String[] items = new String[] { "分享给好友", "分享到朋友圈" };
- private String share_content;
- private String user_id;
-
- private static final int SHARE_SUCCESS = 30;
- private static final int SHARE_FAIL = 31;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- this.setContentView(R.layout.test_share);
- context = TestShare.this;
-
- ShareSDK.initSDK(this);
-
- sina = (RelativeLayout) this.findViewById(R.id.share_sina);
- qq = (RelativeLayout) this.findViewById(R.id.share_qq);
- chat = (RelativeLayout) this.findViewById(R.id.share_chat);
- sms = (RelativeLayout) this.findViewById(R.id.share_sms);
- share_content = this.getResources().getString(R.string.share_content);
- sina.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
-
-
- share(share_content, null, SinaWeibo.NAME);
- }
- });
-
- qq.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
-
-
- share(share_content, null, TencentWeibo.NAME);
- }
- });
-
- chat.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
-
- showChatDialog();
-
- }
- });
-
- sms.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
- sendSms(share_content, "");
-
- }
- });
- }
-
-
- public void share(String text, String photopath, String sharename) {
-
- Platform.ShareParams sp = new SinaWeibo.ShareParams();
- sp.text = text;
-
- if (photopath != null) {
-
- sp.imagePath = photopath;
-
- }
-
- Platform weibo = ShareSDK.getPlatform(context, sharename);
-
-
- weibo.setPlatformActionListener(new PlatformActionListener() {
-
- public void onError(Platform platform, int action, Throwable t) {
-
- Message m = handler.obtainMessage();
- m.what = SHARE_FAIL;
- TestShare.this.handler.sendMessage(m);
- }
-
- public void onComplete(Platform platform, int action,
- HashMap<String, Object> res) {
-
- Message m = handler.obtainMessage();
- m.what = SHARE_SUCCESS;
- TestShare.this.handler.sendMessage(m);
- }
-
- public void onCancel(Platform platform, int action) {
-
- }
-
- });
-
-
- weibo.share(sp);
- }
-
- @Override
- protected void onDestroy() {
-
- ShareSDK.stopSDK(this);
- super.onDestroy();
- }
-
-
- public void sendSms(final String content, final String to) {
- Uri smsToUri = Uri.parse("smsto:".concat(to));
- Intent intent = new Intent(android.content.Intent.ACTION_SENDTO,
- smsToUri);
- intent.putExtra("sms_body", content);
- startActivity(intent);
- }
-
-
- private void showChatDialog() {
-
- new AlertDialog.Builder(this).setTitle("分享到")
- .setItems(items, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case 0:
- share(share_content, null, Wechat.NAME);
- break;
- case 1:
-
- share(share_content, null, WechatMoments.NAME);
- break;
- }
- }
- })
- .setNegativeButton("取消", new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- }).show();
-
- }
-
- private Handler handler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
-
-
- switch (msg.what) {
- case SHARE_SUCCESS:
-
- Toast.makeText(TestShare.this, "分享成功", Toast.LENGTH_SHORT)
- .show();
- break;
- case SHARE_FAIL:
-
- Toast.makeText(TestShare.this, "分享失败", Toast.LENGTH_SHORT)
- .show();
- break;
-
- }
- }
-
- };
-
- }
3、 需要的jar包 ShareSDK-Core.jar 是sdk核心包 ,Wechat是微信核心包,Wechat分享到好友,Wechat-Moments 分享到朋友圈。
另 android-support-v4.jar 需要使用官网下载的。

4、代码混淆
混淆文件在demo中说明,直接更改就可以使用
sharesdk 的使用
原文:http://www.cnblogs.com/Sharley/p/5240567.html