我这里有两种方法
1.友盟的第三方登录
这是友盟官网链接http://mobile.umeng.com/social
简述步骤:
1.点击 SDK及文档
2.选择 Android图标 跳转下一个页面
3.选择 SDK下载 点击下载,选择QQ完整版
选中demo工程(Android Studio):供开发者参考友盟社会化组件代码的实现
点击下载
4.打开下载的文件夹要解压,选中友盟集成工具,选择QQ完整版,Android studio。OK!粘贴umeng_integratetool_result的libs下jar包,注意把res包下的全都考过来
5.返回SDK及文档,工程配置–>完整版配置。这里有大致的步骤
添加的所有权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
添加 sdk中需要的Activity
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent100424468" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize"/>
添加友盟appkey
<meta-data
android:name="UMENG_APPKEY"
android:value="561cae6ae0f55abd990035bf" >
</meta-data>
建立一个application文件,注意要在AndroidManifest文件中配置(如果本身已有,不需要重新建立)
<application
-------
-------
android:name=".App">
然后增加签名文件的密码:
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
[图片实例](https://img-blog.csdn.net/20170714122712104?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXh4X2Jr/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
在application文件中配置三方平台的app:
public class App extends Application {
{
PlatformConfig.setQQZone("100424468","c7394704798a158208a74ab60104f0ba"); }
private static UMShareAPI umShareAPI;
private static App app;
public static App getapp(){return app;}
@Override
public void onCreate() {
super.onCreate();
app=this;
umShareAPI = UMShareAPI.get(this);
x.Ext.init(this);
x.Ext.setDebug(BuildConfig.DEBUG);
}
public static UMShareAPI getUmShareAPI() {
return umShareAPI;
}
}
主MainActivity里的代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@ViewInject(R.id.but)
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化
x.view().inject(this);}
@Override
public void onClick(View v) {
App.getapp().getUmShareAPI().doOauthVerify(this, SHARE_MEDIA.QQ, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
if (i == 0) {
Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
App.getapp().getUmShareAPI().getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, this);
} else if (i == 2) {
String imageurl = map.get("iconurl");
x.image().bind(imageView, imageurl);
}
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
App.getUmShareAPI().onActivityResult(requestCode, resultCode, data);
}
}
在build.gradle导包xutils---- compile ‘org.xutils:xutils:3.5.0’
布局-------只给一个头像图片,有监听设置
<ImageView
android:id="@+id/but"
android:onClick="onClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@mipmap/ic_launcher" />
2.QQ第三方登录
这是别人的博客链接http://blog.csdn.net/sandyran/article/details/53319846
直接粘代码就好