import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
public class MainActivity extends Activity {
private ImageView image;
private TextView deng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
deng = (TextView) findViewById(R.id.deng);
mShareAPI = UMShareAPI.get(this);
deng.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SHARE_MEDIA platform = SHARE_MEDIA.QQ;
mShareAPI.doOauthVerify(MainActivity.this, platform,
umAuthListener);
}
});
}
// 回调监听器,负责监听授权是否成功
private UMAuthListener umAuthListener = new UMAuthListener() {
@Override
public void onComplete(SHARE_MEDIA platform, int action,
Map<String, String> data) {
Toast.makeText(getApplicationContext(), "Authorize succeed",
Toast.LENGTH_SHORT).show();
// 初始化UMShareAPI,然后进行用户信息获取
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> map) {
System.out.println(map.toString());
System.out.println("aaaa--------------------");
// 使用Set集合
Set set = map.keySet();
// 迭代器
Iterator it = set.iterator();
// while循环遍历,使用log打印
while (it.hasNext()) {
Object o = it.next();
Log.e("msg", "key is :" + o + "-----value is :"
+ map.get(o));
}
String name = map.get("screen_name");
String url = map.get("profile_image_url");
deng.setText(name);
ImageLoader.getInstance().displayImage(url,
image);
// 吐司提示授权成功
Toast.makeText(MainActivity.this, "授权登录成功", 0)
.show();
}
@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();
}
};
private UMShareAPI mShareAPI;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mShareAPI.onActivityResult(requestCode, resultCode, data);
}
}
腾讯开放平台的idkey
Application
PlatformConfig.setQQZone("1105114681", "qSYFtMpGEqCitQS0");