第三方lib包
umenglib点过去把这个第三方的lib包克隆或者下载下来直接导入工程中
classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0’
classpath ‘com.github.dcendents:android-maven-gradle-plugin:1.4.1’
maven { url 'https://jitpack.io' }
jcenter() // 或者 mavenCentral()
buildTypes {
release {
// 是否进行混淆
minifyEnabled false
// 混淆文件的位置
signingConfig signingConfigs.debug
proguardFiles ‘proguard-rules.pro’
}
debug {
minifyEnabled false
signingConfig signingConfigs.debug
proguardFiles 'proguard-rules.pro'
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
}
main布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/login_wx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="微信登录" />
<Button
android:id="@+id/login_qq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="QQ登录" />
<Button
android:id="@+id/login_wb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="微博登录" />
<Button
android:id="@+id/shared_wx"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="微信分享" />
<Button
android:id="@+id/shared_qq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="qq分享" />
<Button
android:id="@+id/shared_wb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="微博分享" />
</LinearLayout>
wxapi文件下的WXEntryActivity
package com.umeng.soexample.wxapi;
import com.umeng.weixin.callback.WXCallbackActivity;
public class WXEntryActivity extends WXCallbackActivity {
}
WBShareActivity
package com.umeng.soexample;
import com.umeng.socialize.media.WBShareCallBackActivity;
public class WBShareActivity extends WBShareCallBackActivity {
}
MainActivity
package com.umeng.soexample;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import com.abner.ming.MingUtils;
import com.abner.ming.ResultListener;
import com.abner.ming.UmengBean;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.login_wx).setOnClickListener(this);
findViewById(R.id.login_qq).setOnClickListener(this);
findViewById(R.id.login_wb).setOnClickListener(this);
findViewById(R.id.shared_wx).setOnClickListener(this);
findViewById(R.id.shared_qq).setOnClickListener(this);
findViewById(R.id.shared_wb).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.login_wx://微信
MingUtils.login(this, 1, new ResultListener() {
@Override
public void success(UmengBean umengBean) {
Log.i("success",umengBean.getName());
}
});
break;
case R.id.login_qq://qq
MingUtils.login(this, 0, new ResultListener() {
@Override
public void success(UmengBean umengBean) {
Log.i("success",umengBean.getName());
}
});
break;
case R.id.login_wb://微博
MingUtils.login(this, 2, new ResultListener() {
@Override
public void success(UmengBean umengBean) {
Log.i("success",umengBean.getName());
}
});
break;
case R.id.shared_wx://微信分享
MingUtils.shared(this,1,"朋友,你在干嘛","我再测试呢,你在干嘛","http://tvax4.sinaimg.cn/crop.106.7.294.294.50/005CPEfLly8fr7f98kymnj30eq08x74t.jpg","");
break;
case R.id.shared_qq://qq分享
MingUtils.shared(this,0,"朋友,你在干嘛","我再测试呢,你在干嘛","http://tvax4.sinaimg.cn/crop.106.7.294.294.50/005CPEfLly8fr7f98kymnj30eq08x74t.jpg","");
break;
case R.id.shared_wb://微博分享
MingUtils.shared(this,2,"朋友,你在干嘛","我再测试呢,你在干嘛","http://tvax4.sinaimg.cn/crop.106.7.294.294.50/005CPEfLly8fr7f98kymnj30eq08x74t.jpg","");
break;
}
}
}
清单文件
<!--微信-->
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<!--新浪微博-->
<activity
android:name=".WBShareActivity"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>