一、需要百度搜多友盟官方点击SDK下载
二点击进来会发现三个SDK 下载最后一个
三、按照路径找到这3个jar包并导入
四、按照路径分别把drawable、layout、values里面的文件复制到自己studio相对应的里面
五、导入依赖+权限
compile 'com.umeng.sdk:common:latest.integration'compile 'com.github.bumptech.glide:glide:3.7.0'
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
六、以下代码加入到application中
<activityandroid: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><activityandroid:name="com.tencent.connect.common.AssistActivity"android:theme="@android:style/Theme.Translucent.NoTitleBar"android:configChanges="orientation|keyboardHidden|screenSize"/>
七、写activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="as.bwei.com.qqlogin.MainActivity"><ImageViewandroid:id="@+id/iv_head"android:src="@mipmap/ic_launcher"android:layout_width="wrap_content"android:layout_height="wrap_content" /></android.support.constraint.ConstraintLayout>
八、Mainactivity主代码
public class MainActivity extends AppCompatActivity {private UMShareAPI umShareAPI;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);umShareAPI = UMShareAPI.get(this);final ImageView iv_head = (ImageView) findViewById(R.id.iv_head);iv_head.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {UMAuthListener authListener = new UMAuthListener() {/*** @desc 授权开始的回调* @param platform 平台名称*/@Overridepublic void onStart(SHARE_MEDIA platform) {}/*** @desc 授权成功的回调* @param platform 平台名称* @param action 行为序号,开发者用不上* @param data 用户资料返回*/@Overridepublic void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();Toast.makeText(MainActivity.this, "授权成功后的回调数据,用户信息"+data, Toast.LENGTH_LONG).show();String iconurl = data.get("iconurl");Glide.with(MainActivity.this).load(iconurl).into(iv_head);}/*** @desc 授权失败的回调* @param platform 平台名称* @param action 行为序号,开发者用不上* @param t 错误原因*/@Overridepublic void onError(SHARE_MEDIA platform, int action, Throwable t) {Toast.makeText(MainActivity.this, "失败:" + t.getMessage(),Toast.LENGTH_LONG).show();}/*** @desc 授权取消的回调* @param platform 平台名称* @param action 行为序号,开发者用不上*/@Overridepublic void onCancel(SHARE_MEDIA platform, int action) {Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();}};umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, authListener);}});}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);}
}
九、最后注册
public class App extends Application{@Overridepublic void onCreate() {super.onCreate();UMConfigure.init(this,"5a12384aa40fa3551f0001d1","umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");UMConfigure.setLogEnabled(true);}
}