80,337
社区成员
发帖
与我相关
我的任务
分享
类已经继承了 public class AddFriendsActivity extends Activity implements OnClickListener, Callback, PlatformActionListener 。
private void showShareCircle(){
ShareSDK.initSDK(this);
Platform.ShareParams sp = new WechatMoments.ShareParams();
sp.setTitle("test");
sp.text = "test";
sp.setImageUrl("http://192.168.2.5:8808/appImages/Head/1000.png");
sp.setUrl("http://192.168.2.5:8808/AppService/app");
Platform platform = ShareSDK.getPlatform(AddFriendsActivity.this, WechatMoments.NAME);
platform.setPlatformActionListener(this);
platform.share(sp);
}
//回调方法
public void onComplete(Platform plat, int action,
HashMap<String, Object> res) {
Message msg = new Message();
msg.arg1 = 1;
msg.arg2 = action;
msg.obj = plat;
UIHandler.sendMessage(msg, this);
}
public void onCancel(Platform plat, int action) {
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) {
t.printStackTrace();
Message msg = new Message();
msg.arg1 = 2;
msg.arg2 = action;
msg.obj = t;
UIHandler.sendMessage(msg, this);
}
public boolean handleMessage(Message msg) {
String text = "msg.arg2";
switch (msg.arg1) {
case 1: {
// 成功
Platform plat = (Platform) msg.obj;
text = plat.getName() + " completed at " + text;
}
break;
case 2: {
// 失败
if ("WechatClientNotExistException".equals(msg.obj.getClass().getSimpleName())) {
text = this.getString(R.string.wechat_client_inavailable);
}
else if ("WechatTimelineNotSupportedException".equals(msg.obj.getClass().getSimpleName())) {
text = this.getString(R.string.wechat_client_inavailable);
}
else {
text = this.getString(R.string.share_failed);
}
}
break;
case 3: {
// 取消
Platform plat = (Platform) msg.obj;
text = plat.getName() + " canceled at " + text;
}
break;
}
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
return false;
}