友盟第三方登入
1.首先包名必須是com.umeng.soexample
2.匯入相關的jar包
3.配置清單檔案Activity和所需的許可權
4.匯入相關的資原始檔drawable,values,layout
5.建立包 wxapi,建立類WXEntryActivity繼承WXCallbackActivity
6.建立自己的Application
package com.umeng.soexample;
import android.app.Application;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
public class UMapplication extends Application {
@Override
public void onCreate() {
super.onCreate();
UMConfigure.setLogEnabled(true);
UMConfigure.init(this,“5a12384aa40fa3551f0001d1”
,“umeng”,UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
PlatformConfig.setQQZone(“100424468”, “c7394704798a158208a74ab60104f0ba”);
PlatformConfig.setWeixin(“wxdc1e388c3822c80b”, “3baf1193c85774b3fd9d18447d76cab0”);
}
}
7.簡單封裝第三方登入類
package com.umeng.soexample.utils;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.soexample.MainActivity;
import java.util.Map;
import java.util.Set;
public class UmActivity {
public UmActivity(){
};
private Chuan chuan;
public UmActivity uMengLogin(final Context context, SHARE_MEDIA share){
UMShareAPI mUMAPI = UMShareAPI.get(context);
UMAuthListener umAuthListener = new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
chuan.OnChuan(map);
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
Toast.makeText(context.getApplicationContext(), "Authorize fail",
Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
Toast.makeText(context.getApplicationContext(), "Authorize cancel",
Toast.LENGTH_SHORT).show();
}
};
mUMAPI.getPlatformInfo((Activity) context,share,umAuthListener);
return this;
}
public interface Chuan{
void OnChuan(Map<String,String> map1);
}
public void setChuan(Chuan chuan) {
this.chuan = chuan;
}
}
8.使用
qq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, “fasdfsdf”, Toast.LENGTH_SHORT).show();
UMShareConfig config = new UMShareConfig();
config.isNeedAuthOnGetUserInfo(true);
UMShareAPI.get(MainActivity.this).setShareConfig(config);
new UmActivity().uMengLogin(MainActivity.this,SHARE_MEDIA.QQ).setChuan(new UmActivity.Chuan() {
@Override
public void OnChuan(Map<String, String> map1) {
// textView.setText(map1.get(“screen_name”));
//pass.setText(map1.get(“openid”));
String profile_image_url = map1.get(“profile_image_url”);
String screen_name = map1.get(“screen_name”);
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra(“pro”,profile_image_url);
intent.putExtra(“name”,screen_name);
startActivity(intent);
Toast.makeText(MainActivity.this, map1.toString(), Toast.LENGTH_SHORT).show();
}
});
}
});
weixin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UMShareConfig config = new UMShareConfig();
config.isNeedAuthOnGetUserInfo(true);
UMShareAPI.get(MainActivity.this).setShareConfig(config);
new UmActivity().uMengLogin(MainActivity.this,SHARE_MEDIA.WEIXIN).setChuan(new UmActivity.Chuan() {
@Override
public void OnChuan(Map<String, String> map1) {
String profile_image_url = map1.get("profile_image_url");
String screen_name = map1.get("screen_name");
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("pro",profile_image_url);
intent.putExtra("name",screen_name);
startActivity(intent);
}
});