1 . 分享(前提是集成了sdk,配置好了Key),只要实现点击事件,调用shareSina();
ShareSDK.initSDK(this);
private void shareSina() { //实现一键分享 /* * * final OnekeyShare oks = new OnekeyShare(); * oks.disableSSOWhenAuthorize(); oks.setTitle("听途智能游"); * oks.setTitleUrl("http://www.etoury.com/"); * oks.setText(getString(R.string.share_text)); // qq不能加这个 // * oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片 * oks.setUrl("http://www.etoury.com/"); // 加这句微博报错 // * oks.setImageUrl("http://7sby7r.com1.z0.glb.clouddn.com/CYSJ_02.jpg"); * oks.show(this); */ //不用一键分享 ShareParams sp = new ShareParams(); sp.setShareType(Platform.SHARE_WEBPAGE);// 非常重要:一定要设置分享属 sp.setText("一款覆盖20多个国家,1000多个目的地的免费智能导游APP。同时还提供强大的旅行工具箱,帮您解决行程中遇到的一切难题。让您不用花钱,便可获悉旅行途中的一切。想走就走,彻底摆脱黑导游!http://www.etoury.com/"); // sp.setImageUrl("http://7sby7r.com1.z0.glb.clouddn.com/CYSJ_02.jpg"); Platform sinaWeibo = ShareSDK.getPlatform(SinaWeibo.NAME); sinaWeibo.setPlatformActionListener(ActivityAbout.this); sinaWeibo.share(sp); }
@Override protected void onDestroy() { super.onDestroy(); ShareSDK.stopSDK(this); } @Override public void onCancel(Platform arg0, int arg1) { // 取消 handler.sendEmptyMessage(5); } @Override public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) { if (arg0.getName().equals(SinaWeibo.NAME)) { handler.sendEmptyMessage(1); } else if (arg0.getName().equals(Wechat.NAME)) { handler.sendEmptyMessage(2); } else if (arg0.getName().equals(WechatMoments.NAME)) { handler.sendEmptyMessage(3); } else if (arg0.getName().equals(QQ.NAME)) { handler.sendEmptyMessage(4); } } @Override public void onError(Platform arg0, int arg1, Throwable arg2) { Message msg = new Message(); msg.what = 6; msg.obj = arg2.getMessage(); handler.sendMessage(msg); } Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: /* * Toast.makeText(getApplicationContext(), "微博分享成功", * Toast.LENGTH_LONG).show(); */ System.out.println("微博分享成功"); break; case 2: /* * Toast.makeText(getApplicationContext(), "微信分享成功", * Toast.LENGTH_LONG).show(); */ System.out.println("微信分享成功"); break; case 3: /* * Toast.makeText(getApplicationContext(), "朋友圈分享成功", * Toast.LENGTH_LONG).show(); */ System.out.println("朋友圈分享成功"); break; case 4: /* * Toast.makeText(getApplicationContext(), "QQ分享成功", * Toast.LENGTH_LONG).show(); */ System.out.println("QQ分享成功"); break; case 5: Toast.makeText(getApplicationContext(), "取消分享", Toast.LENGTH_LONG).show(); break; case 6: /* * Toast.makeText(getApplicationContext(), "分享失败啊" + msg.obj, * Toast.LENGTH_LONG).show(); */ System.out.println(msg.obj + ""); break; default: break; } }; };