从网站:http://bbs.umeng.com/forum.php?mod=viewthread&tid=5498&highlight=%E5%BE%AE%E4%BF%A1%E6%8E%88%E6%9D%83 整理而来。
android 微信登录实现方法
添加
1
2
3
4
5
6
|
/
/
wx
967
daebe
835
fbeac是你在微信开发平台注册应用的AppID
,
这里需要替换成你注册的AppID
String appID
=
"wx967daebe835fbeac"
;
String appSecret
=
"5fa9e68ca3970e87a1f83e563c8dcbce"
;
/
/
添加微信平台
UMWXHandler wxHandler
=
new
UMWXHandler
(
getActivity
(
)
,
appId
,
appSecret
)
;
wxHandler.addToSocialSDK
(
)
;
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
|
mController.doOauthVerify(MainActivity.
this
, SHARE_MEDIA.WEIXIN,
new
UMAuthListener() {
@Override
public
void
onError(SocializeException e, SHARE_MEDIA platform) {
}
@Override
public
void
onComplete(Bundle value, SHARE_MEDIA platform) {
if
(value !=
null
&& !TextUtils.isEmpty(value.getString(
"uid"
))) {
Toast.makeText(MainActivity.
this
,
"授权成功."
, Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.
this
,
"授权失败"
, Toast.LENGTH_SHORT).show();
}
}
@Override
public
void
onCancel(SHARE_MEDIA platform) {}
@Override
public
void
onStart(SHARE_MEDIA platform) {}
});
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
mController.getPlatformInfo(MainActivity.
this
, SHARE_MEDIA.WEIXIN,
new
UMDataListener() {
@Override
public
void
onStart() {
Toast.makeText(MainActivity.
this
,
"获取平台数据开始..."
, Toast.LENGTH_SHORT).show();
}
@Override
public
void
onComplete(
int
status, Map
if
(status ==
200
&& info !=
null
){
StringBuilder sb =
new
StringBuilder();
Set
for
(String key : keys){
sb.append(key+
"="
+info.get(key).toString()+
"\r\n"
);
}
Log.d(
"TestData"
,sb.toString());
}
else
{
Log.d(
"TestData"
,
"发生错误:"
+status);
}
}
});
|
1
2
3
4
5
6
|
android:name=
".wxapi.WXEntryActivity"
android:theme=
"@android:style/Theme.Translucent.NoTitleBar"
android:configChanges=
"keyboardHidden|orientation|screenSize"
android:exported=
"true"
android:screenOrientation=
"portrait"
/>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
|
mSnsPostListener =
new
SnsPostListener() {
@Override
public
void
onStart() {
}
@Override
public
void
onComplete(SHARE_MEDIA platform,
int
stCode,
SocializeEntity entity) {
if
(stCode ==
200
) {
Toast.makeText(MainActivity.
this
,
"分享成功"
, Toast.LENGTH_SHORT)
.show();
}
else
{
Toast.makeText(MainActivity.
this
,
"分享失败 : error code : "
+ stCode, Toast.LENGTH_SHORT)
.show();
}
}
};
|