解决方法:
https://open.weibo.com/apps/283601501/info/advanced
配置授权回调和取消授权回调页面;输入https://api.weibo.com/oauth2/default.html
国内领先的第三方全域数据服务商提供数据统计、消息推送、移动广告监测、社会化分享(包含第三方的登录)等服务。
登录网站 https://www.umeng.com/,注册账号,进入工作台,点击移动统计,如图,创建项目,获取appkey,并记录。
具体配置文档地址:https://developer.umeng.com/docs/128606/detail/129635
buildscript和 allprojects 配置maven
buildscript {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/umsdk/release' }
}
}
1.下载sdk最新版https://developer.umeng.com/sdk, 选择自己需要的功能。
2. 解压sdk ,把解压后的文件夹里的jar 和图片资源,layout 资源,复制到自己的项目里。记得jar包 导入依赖。
友盟是一个分享平台,它是集成了其他公司的分享业务,它自身是没有分享功能的。比如微信、微博、QQ
微信
在包名目录下创建wxapi文件夹,新建一个名为WXEntryActivity的activity继承WXCallbackActivity。
QQ与新浪
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
}
<activity
android:name="com.umeng.socialize.media.WBShareCallBackActivity"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false"
>
</activity>
<activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
android:configChanges="keyboardHidden|orientation"
android:exported="false"
android:windowSoftInputMode="adjustResize"
>
</activity>
<activity
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:name="com.sina.weibo.sdk.share.WbShareTransActivity">
<intent-filter>
<action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
新浪
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
微信
<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:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize"/>
<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"/>
根据自己需要配置不同的分享平台
@Override
public void onCreate() {
super.onCreate();
UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
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");
PlatformConfig.setYnote("9c82bf470cba7bd2f1819b0ee26f86c6ce670e9b");
}
androidstudio 有自己默认的debug的签名。位置在:C:\Users\chen.android\debug.keystore,找到自己电脑的签名。复制到app的根目录下。配置如下
buildTypes {
//debug 模式
debug{
minifyEnabled false
// 签名使用signingConfigs 模块的配置
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
}
带面板的分享
new ShareAction(MainActivity.this).withText("hello").setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN)
.setCallback(umShareListener).open();
不带面板的分享
new ShareAction(MainActivity.this)
.setPlatform(SHARE_MEDIA.QQ)//传入平台
.withText("hello")//分享内容
.setCallback(umShareListener)//回调监听器
.share();
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(ShareDetailActivity.this,"成功 了",Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享失败的回调
* @param platform 平台类型
* @param t 错误原因
*/
@Override
public void onError(SHARE_MEDIA platform, Throwable t) {
Toast.makeText(ShareDetailActivity.this,"失 败"+t.getMessage(),Toast.LENGTH_LONG).show();
}
/**
* @descrption 分享取消的回调
* @param platform 平台类型
*/
@Override
public void onCancel(SHARE_MEDIA platform) {
Toast.makeText(ShareDetailActivity.this,"取消 了",Toast.LENGTH_LONG).show();
}
};
private void login() {
//
UMShareAPI.get(this) .getPlatformInfo(MainActivity.this, SHARE_MEDIA.SINA, new UMAuthListener() {
@Override
public void onStart(SHARE_MEDIA share_media) {
Log.d(TAG, "onStart: ");
}
@Override
public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {
Log.d(TAG, "onComplete: ");
// 打印用户信息
for (Map.Entry<String,String> entry:map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
}
@Override
public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
Log.d(TAG, "onError: ");
}
@Override
public void onCancel(SHARE_MEDIA share_media, int i) {
Log.d(TAG, "onCancel: ");
}
});
}