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