详细:http://dev.umeng.com/social/android/quick-integration#3
引入SDK,jar包
修改AndroidManiFest 加入权限,activity
添加友盟appkey
配置各个平台的appkey
然后就可以分享:
new ShareAction(MainActivity.this).setPlatform(SHARE_MEDIA.QQ)
.withText("hello")
.setCallback(umShareListener)
.share();
监听:
private UMShareListener umShareListener = new UMShareListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
//分享开始的回调
}
@Override
public void onResult(SHARE_MEDIA platform) {
Log.d("plat","platform"+platform);
Toast.makeText(MainActivity.this, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(SHARE_MEDIA platform, Throwable t) {
Toast.makeText(MainActivity.this,platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
if(t!=null){
Log.d("throw","throw:"+t.getMessage());
}
}
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this,platform + " 分享取消了", Toast.LENGTH_SHORT).show();
}
};
mShareAPI.getPlatformInfo(UserinfoActivity.this, SHARE_MEDIA.SINA, umAuthListener);
其中umAuthListener为授权回调,构建如下,其中授权成功会回调onComplete,取消授权回调onCancel,授权错误回调onError,对应的错误信息可以用过onError的Throwable参数来打印
private UMAuthListener umAuthListener = new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA platform) {
//授权开始的回调
}
@Override
public void onComplete(SHARE_MEDIA platform, int action, Map data) {
Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(SHARE_MEDIA platform, int action, Throwable t) {
Toast.makeText( getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel(SHARE_MEDIA platform, int action) {
Toast.makeText( getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show();
}};