分享+登陆

package com.example.zvvvvvvvvv;


import java.util.Map;


import com.loopj.android.image.SmartImageView;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;


import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {


private UMShareAPI mShareAPI;


final SHARE_MEDIA[] displaylist = new SHARE_MEDIA[] { SHARE_MEDIA.WEIXIN,
SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.SINA, SHARE_MEDIA.QQ,
SHARE_MEDIA.QZONE, SHARE_MEDIA.DOUBAN };






private TextView tv;


private SmartImageView img;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img=(SmartImageView)findViewById(R.id.imageView1);
tv=(TextView)findViewById(R.id.textView1);
}


public void three(View v) {
mShareAPI = UMShareAPI.get(getApplicationContext());
SHARE_MEDIA platform = SHARE_MEDIA.QQ;
mShareAPI.doOauthVerify(this, platform, umAuthListener);


}


public void fenxiang(View v) {
UMImage image = new UMImage(MainActivity.this,
BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher));
new ShareAction(this).setDisplayList(displaylist).withText("呵呵")
.withTitle("title").withTargetUrl("http://www.baidu.com")
.withMedia(image).setListenerList(new UMShareListener() {
@Override
public void onResult(SHARE_MEDIA 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();
}


@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, platform + " 分享取消了",
Toast.LENGTH_SHORT).show();
}
}).open();


}


private UMAuthListener umAuthListener = new UMAuthListener() {
@Override
public void onComplete(SHARE_MEDIA platform, int action,
Map<String, String> data) {
mShareAPI.getPlatformInfo(MainActivity.this, platform, new UMAuthListener() {

@Override
public void onError(SHARE_MEDIA arg0, int arg1, Throwable arg2) {
// TODO Auto-generated method stub

}

@Override
public void onComplete(SHARE_MEDIA arg0, int arg1, Map<String, String> arg2) {
for (String map : arg2.keySet()) {
System.out.println("key   "+map+"          value    "+arg2.get(map));
img.setImageUrl(arg2.get("profile_image_url"));
tv.setText(arg2.get("screen_name"));
}

}

@Override
public void onCancel(SHARE_MEDIA arg0, int arg1) {
// TODO Auto-generated method stub

}
});
}


@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();
}
};


// @Override
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
// mShareAPI.onActivityResult(requestCode, resultCode, data);
// UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
// }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);
if(requestCode==10103){
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
System.out.println(requestCode+"   "+resultCode+"   "+data);
}
if(requestCode==11101){
mShareAPI.onActivityResult(requestCode, resultCode, data);
System.out.println(requestCode+"   "+resultCode+"   "+data);
}
}



}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值