第三方登录与分享

来源:互联网 发布:java两种多态机制 编辑:程序博客网 时间:2024/04/24 03:57
Mob官方分享网址(参考)
http://wiki.mob.com/android_快速集成指南/?


Mob官方分享网址(参考)?
http://wiki.mob.com/第三方登录/




配置AndroidManifest.xml


1、添加权限
<uses-permission android:name="android.permission.GET_TASKS" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
 <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
 <!-- 蓝牙分享所需的权限 -->
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />


2、添加activity信息


(注意: tencent后面的appid要保持和您配置的QQ的appid一致)
<activity
     android:name="com.mob.tools.MobUIShell"
     android:theme="@android:style/Theme.Translucent.NoTitleBar"
     android:configChanges="keyboardHidden|orientation|screenSize"
     android:screenOrientation="portrait"
     android:windowSoftInputMode="stateHidden|adjustResize" >


     <intent-filter>
         <data android:scheme="tencent100371282" />
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.BROWSABLE" />
         <category android:name="android.intent.category.DEFAULT" />
     </intent-filter>


    <!-- 调用新浪原生SDK,需要注册的回调activity -->
    <intent-filter>
        <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
 </activity>


4、替换mob后台申请的Appkey与各个平台申请的key


 AppKey = "13e042067ff92"/> <!-- 修改成你在sharesdk后台注册的应用的appkey"-->


<QZone
        Id="3"
        SortId="3"
        AppId="100371282"
        AppKey="KP6Q3lc0xRT1DsIp"
        Enable="true" />




<QQ
        Id="7"
        SortId="7"
        AppId="100371282"
        AppKey="KP6Q3lc0xRT1DsIp"
        ShareByAppClient="true"
        Enable="true" />


第三步:添加分享代码
在您的代码中调用此方法,即可打开一键分享功能进行分享


private void showShare() {
 ShareSDK.initSDK(this);
 OnekeyShare oks = new OnekeyShare();
 //关闭sso授权
 oks.disableSSOWhenAuthorize(); 


// 分享时Notification的图标和文字  2.5.9以后的版本不调用此方法
 //oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
 // title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
 oks.setTitle(getString(R.string.share));
 // titleUrl是标题的网络链接,仅在人人网和QQ空间使用
 oks.setTitleUrl("http://sharesdk.cn");
 // text是分享文本,所有平台都需要这个字段
 oks.setText("我是分享文本");
 // imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
 //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
 // url仅在微信(包括好友和朋友圈)中使用
 oks.setUrl("http://sharesdk.cn");
 // comment是我对这条分享的评论,仅在人人网和QQ空间使用
 oks.setComment("我是测试评论文本");
 // site是分享此内容的网站名称,仅在QQ空间使用
 oks.setSite(getString(R.string.app_name));
 // siteUrl是分享此内容的网站地址,仅在QQ空间使用
 oks.setSiteUrl("http://sharesdk.cn");


// 启动分享GUI
 oks.show(this);
 }


QQ第三方登录


                                ShareSDK.initSDK(this);
Platform platform11 = ShareSDK.getPlatform(QQ.NAME);
// platform11.SSOSetting(true);
platform11.authorize();
platform11.showUser(null);// 必须要加的要不然不行!这个才是授权的!
tm = (TelephonyManager) MainActivity.this
.getSystemService(TELEPHONY_SERVICE);
imi = tm.getDeviceId();
platform11
.setPlatformActionListener(new PlatformActionListener() {
@Override//失败代码
public void onError(Platform platform11, int arg1,
Throwable arg2) {
// 弹出失败窗口
}


@SuppressLint("SimpleDateFormat")
@Override
public void onComplete(Platform platform11,
int arg1, HashMap<String, Object> arg2) {


System.out.println("登录成功。。。。");
                                  
String userId = platform11.getDb().getUserId();
//qq头像
final String userIcon = platform11.getDb()
.getUserIcon();
//qq名称
String userName = platform11.getDb()
.getUserName();
String token = platform11.getDb().getToken();
long expiresTime = platform11.getDb()
.getExpiresTime();
SimpleDateFormat sdf3 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm");
System.out.println("userId    " + userId);
System.out.println("userName    " + userName);
System.out.println("token     " + token);
System.out.println("expiresTime  "
+ sdf3.format(expiresTime));

//加载qq头像
runOnUiThread(new Runnable() {
public void run() {
ImageLoader.getInstance().displayImage(
userIcon, image);
}
});


}


@Override//登录取消
public void onCancel(Platform arg0, int arg1) {


}
});
0 0