uMeng第三方登錄
public class UmengLogin extends Activity{
static UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.login");
/** QQ第三方登錄 */
public static void QQ_login(final Context mContext){
mController.doOauthVerify(mContext, SHARE_MEDIA.QQ, new UMAuthListener() {
public void onStart(SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權開始", Toast.LENGTH_SHORT).show();
}
public void onError(SocializeException e, SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權錯誤", Toast.LENGTH_SHORT).show();
}
public void onComplete(Bundle value, SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權完成", Toast.LENGTH_SHORT).show();
//獲取相關授權信息
mController.getPlatformInfo(mContext, SHARE_MEDIA.QQ, new UMDataListener() {
public void onStart() {
Toast.makeText(mContext, "獲取平臺數據開始...", Toast.LENGTH_SHORT).show();
}
public void onComplete(int status, Map<String, Object> info) {
if(status == 200 && info != null){
StringBuilder sb = new StringBuilder();
Set<String> keys = info.keySet();
for(String key : keys){
sb.append(key+"="+info.get(key).toString()+"\r\n");
}
Log.d("TestData",sb.toString());
//發送廣播,把頭像的url和用戶名發送出去
Intent intent=new Intent();
intent.setAction("org.crazyit.action.CRAZY_BROADCAST");
intent.putExtra("tou_url", info.get("profile_image_url").toString());
intent.putExtra("tou_name", info.get("screen_name").toString());
mContext.sendBroadcast(intent);
}else{
Log.d("TestData","發生錯誤:"+status);
}
}
});
}
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權取消", Toast.LENGTH_SHORT).show();
}
} );
}
/** 新浪第三方登錄 */
public static void sina_login(final Context mContext){
mController.doOauthVerify(mContext, SHARE_MEDIA.SINA,new UMAuthListener() {
public void onError(SocializeException e, SHARE_MEDIA platform) {
}
public void onComplete(Bundle value, SHARE_MEDIA platform) {
if (value != null && !TextUtils.isEmpty(value.getString("uid"))) {
Toast.makeText(mContext, "授權成功.",Toast.LENGTH_SHORT).show();
//獲取相關授權信息
mController.getPlatformInfo(mContext, SHARE_MEDIA.QQ, new UMDataListener() {
public void onStart() {
Toast.makeText(mContext, "獲取平臺數據開始...", Toast.LENGTH_SHORT).show();
}
public void onComplete(int status, Map<String, Object> info) {
if(status == 200 && info != null){
StringBuilder sb = new StringBuilder();
Set<String> keys = info.keySet();
for(String key : keys){
sb.append(key+"="+info.get(key).toString()+"\r\n");
}
Log.d("TestData",sb.toString());
//發送廣播,把頭像的url和用戶名發送出去
Intent intent=new Intent();
intent.setAction("org.crazyit.action.CRAZY_BROADCAST");
intent.putExtra("tou_url", info.get("profile_image_url").toString());
intent.putExtra("tou_name", info.get("screen_name").toString());
mContext.sendBroadcast(intent);
}else{
Log.d("TestData","發生錯誤:"+status);
}
}
});
} else {
Toast.makeText(mContext, "授權失敗",Toast.LENGTH_SHORT).show();
}
}
public void onCancel(SHARE_MEDIA platform) {}
public void onStart(SHARE_MEDIA platform) {}
});
}
}
static UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.login");
/** QQ第三方登錄 */
public static void QQ_login(final Context mContext){
mController.doOauthVerify(mContext, SHARE_MEDIA.QQ, new UMAuthListener() {
public void onStart(SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權開始", Toast.LENGTH_SHORT).show();
}
public void onError(SocializeException e, SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權錯誤", Toast.LENGTH_SHORT).show();
}
public void onComplete(Bundle value, SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權完成", Toast.LENGTH_SHORT).show();
//獲取相關授權信息
mController.getPlatformInfo(mContext, SHARE_MEDIA.QQ, new UMDataListener() {
public void onStart() {
Toast.makeText(mContext, "獲取平臺數據開始...", Toast.LENGTH_SHORT).show();
}
public void onComplete(int status, Map<String, Object> info) {
if(status == 200 && info != null){
StringBuilder sb = new StringBuilder();
Set<String> keys = info.keySet();
for(String key : keys){
sb.append(key+"="+info.get(key).toString()+"\r\n");
}
Log.d("TestData",sb.toString());
//發送廣播,把頭像的url和用戶名發送出去
Intent intent=new Intent();
intent.setAction("org.crazyit.action.CRAZY_BROADCAST");
intent.putExtra("tou_url", info.get("profile_image_url").toString());
intent.putExtra("tou_name", info.get("screen_name").toString());
mContext.sendBroadcast(intent);
}else{
Log.d("TestData","發生錯誤:"+status);
}
}
});
}
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(mContext, "授權取消", Toast.LENGTH_SHORT).show();
}
} );
}
/** 新浪第三方登錄 */
public static void sina_login(final Context mContext){
mController.doOauthVerify(mContext, SHARE_MEDIA.SINA,new UMAuthListener() {
public void onError(SocializeException e, SHARE_MEDIA platform) {
}
public void onComplete(Bundle value, SHARE_MEDIA platform) {
if (value != null && !TextUtils.isEmpty(value.getString("uid"))) {
Toast.makeText(mContext, "授權成功.",Toast.LENGTH_SHORT).show();
//獲取相關授權信息
mController.getPlatformInfo(mContext, SHARE_MEDIA.QQ, new UMDataListener() {
public void onStart() {
Toast.makeText(mContext, "獲取平臺數據開始...", Toast.LENGTH_SHORT).show();
}
public void onComplete(int status, Map<String, Object> info) {
if(status == 200 && info != null){
StringBuilder sb = new StringBuilder();
Set<String> keys = info.keySet();
for(String key : keys){
sb.append(key+"="+info.get(key).toString()+"\r\n");
}
Log.d("TestData",sb.toString());
//發送廣播,把頭像的url和用戶名發送出去
Intent intent=new Intent();
intent.setAction("org.crazyit.action.CRAZY_BROADCAST");
intent.putExtra("tou_url", info.get("profile_image_url").toString());
intent.putExtra("tou_name", info.get("screen_name").toString());
mContext.sendBroadcast(intent);
}else{
Log.d("TestData","發生錯誤:"+status);
}
}
});
} else {
Toast.makeText(mContext, "授權失敗",Toast.LENGTH_SHORT).show();
}
}
public void onCancel(SHARE_MEDIA platform) {}
public void onStart(SHARE_MEDIA platform) {}
});
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.