清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.umeng.soexample">
<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.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</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:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="UMENG_APPKEY"
android:value="5c08d2fbb465f54009000122"></meta-data>
</application>
</manifest>
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button mDai, mNoDai;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews() {
mDai = findViewById(R.id.Dai_MB_Btn);
mDai.setOnClickListener(this);
mNoDai = findViewById(R.id.No_Dai_MB_Btn);
mNoDai.setOnClickListener(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Dai_MB_Btn:
UMImage umImage = new UMImage(this, R.drawable.umeng_socialize_wxcircle);
new ShareAction(MainActivity.this).withText("hello").withMedia(umImage).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.QZONE)
//分享的监听
.setCallback(shareListener).open();
break;
case R.id.No_Dai_MB_Btn:
break;
}
}
//设置回调监听
private UMShareListener shareListener = new UMShareListener() {
/**
* @descrption 分享开始的回调
* @param platform 平台类型
*/
@Override
public void onStart(SHARE_MEDIA platform) {
}
/**
* @descrption 分享成功的回调
* @param platform 平台类型
*/
@Override
public void onResult(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享失败的回调
* @param platform 平台类型
* @param t 错误原因
*/
@Override
public void onError(SHARE_MEDIA platform, Throwable t) {
Toast.makeText(MainActivity.this, "失败" + t.getMessage(), Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享取消的回调
* @param platform 平台类型
*/
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();
}
};
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
UMConfigure.init(this, "5a12384aa40fa3551f0001d1"
, "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
//开启log打印 报错会给你提示
UMConfigure.setLogEnabled(true);
PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
//豆瓣RENREN平台目前只能在服务器端配置
PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf");
PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO");
PlatformConfig.setAlipay("2015111700822536");
PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e");
PlatformConfig.setPinterest("1439206");
PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f");
PlatformConfig.setDing("dingoalmlnohc0wggfedpk");
PlatformConfig.setVKontakte("5764965", "5My6SNliAaLxEm3Lyd9J");
PlatformConfig.setDropbox("oz8v5apet3arcdy", "h7p2pjbzkkxt02a");
}
}
public class WXEntryActivity extends WXCallbackActivity {
}
qq:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button mDai, mNoDai;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews() {
mDai = findViewById(R.id.Dai_MB_Btn);
mDai.setOnClickListener(this);
mNoDai = findViewById(R.id.No_Dai_MB_Btn);
mNoDai.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Dai_MB_Btn:
/*UMImage umImage = new UMImage(this, R.drawable.umeng_socialize_wxcircle);
new ShareAction(MainActivity.this).withText("hello").withMedia(umImage).setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.QZONE)
//分享的监听
.setCallback(shareListener).open();*/
UMShareAPI.get(MainActivity.this).getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, authListeners);
break;
case R.id.No_Dai_MB_Btn:
break;
}
}
//设置回调监听
private UMShareListener shareListener = new UMShareListener() {
/**
* @descrption 分享开始的回调
* @param platform 平台类型
*/
@Override
public void onStart(SHARE_MEDIA platform) {
}
/**
* @descrption 分享成功的回调
* @param platform 平台类型
*/
@Override
public void onResult(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享失败的回调
* @param platform 平台类型
* @param t 错误原因
*/
@Override
public void onError(SHARE_MEDIA platform, Throwable t) {
Toast.makeText(MainActivity.this, "失败" + t.getMessage(), Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享取消的回调
* @param platform 平台类型
*/
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();
}
};
UMAuthListener authListeners = new UMAuthListener() {
/**
* @desc 授权开始的回调
* @param platform 平台名称
*/
@Override
public void onStart(SHARE_MEDIA platform) {
}
/**
* @desc 授权成功的回调
* @param platform 平台名称
* @param action 行为序号,开发者用不上
* @param data 用户资料返回
*/
@Override
public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();
}
/**
* @desc 授权失败的回调
* @param platform 平台名称
* @param action 行为序号,开发者用不上
* @param t 错误原因
*/
@Override
public void onError(SHARE_MEDIA platform, int action, Throwable t) {
Toast.makeText(MainActivity.this, "失败:" + t.getMessage(), Toast.LENGTH_LONG).show();
}
/**
* @desc 授权取消的回调
* @param platform 平台名称
* @param action 行为序号,开发者用不上
*/
@Override
public void onCancel(SHARE_MEDIA platform, int action) {
Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
Toast.makeText(MainActivity.this,"登录成功了啊啊啊啊啊啊啊",Toast.LENGTH_SHORT).show();
}
}
头像: