主要场景:
- 将分享内容分享到 QQ、微信、新浪微博、Facebook、Twitter 等主要的社交平台。
- 获得 QQ、微信、新浪微博、Facebook、Twitter 等主要平台授权。
- 获取 QQ、微信、新浪微博、Facebook、Twitter 等主要平台的个人信息,用于第三方登录。
集成步骤
- 在 gradle 配置 jcenter。
- manifest.xml配置
- 配置第三方平台信息。
- 配置微信回调(如不需要分享到微信,可跳过)。
- 配置项目签名。
- 参考 example 工程或者接口文档使用 JShare SDK。
Gradle配置
- Project 根目录的主 gradle 中配置了 jcenter 支持。
buildscript {
repositories {
jcenter()
}
......
}
allprojects {
repositories {
jcenter()
}
}
- 在 module 的 gradle 中添加依赖和 AndroidManifest 的替换变量。
android {
......
defaultConfig {
applicationId "com.xxx.xxx" //极光控制台创建应用时填写的应用包名.
......
ndk {
//选择要添加的对应 cpu 类型的.so 库。
abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a'
// 还可以添加 'x86', 'x86_64', 'mips', 'mips64'
}
manifestPlaceholders = [
JSHARE_PKGNAME : applicationId,
JPUSH_APPKEY : "你的 appkey", //极光控制台创建应用得到的 AppKey.
JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
TENCENT_APPID: " QQ 开发者应用的 appID ",//腾讯开放平台注册应用得到的 appId
FACEBOOK_APPID: " facebook 开发者应用的 appID ",// facebook 注册应用得到的 appId
]
......
}
......
}
dependencies {
......
compile 'cn.jiguang.sdk:jshare:1.5.0' // 此处以 JShare 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jshare-qqmodel:1.5.0' // 此处以 jshare-qqmodel 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jshare-wechatmodel:1.5.0' // 此处以 jshare-wechatmodel 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jshare-sinamodel:1.5.0' // 此处以 jshare-sinamodel 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jshare-facebookmodel:1.5.0' // 此处以 jshare-facebookmodel 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jshare-twittermodel:1.5.0' // 此处以 jshare-twittermodel 1.5.0 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
compile 'cn.jiguang.sdk:jcore:1.1.7' // 此处以 JCore 1.1.7 版本为例,具体版本请参考压缩包 libs 的 jar 包版本。
......
}
manifest.xml
- 权限配置
<!-- Required -->
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Optional. Required for location feature -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
- SDK 核心功能(分享回调可以不写)
<!-- Required SDK 核心功能-->
<activity
android:name="cn.jiguang.share.android.ui.JiguangShellActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize">
<!-- Optional QQ 分享回调-->
<!-- scheme为“tencent” 前缀再加上 QQ 开发者应用的 appID;例如 appID为123456,则 scheme=“tencent123456” -->
<intent-filter>
<data android:scheme="tencent+appID" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- Optional 新浪微博分享回调 -->
<intent-filter>
<action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- Optional 新浪微博私信回调 -->
<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="jsharesdk" android:host="sinaweibo"/>
</intent-filter>
</activity>
配置第三方平台信息
JGShareSDK.xml 示例
<?xml version="1.0" encoding="utf-8"?>
<DevInfor>
<!-- 如果不需要支持某平台,可缺省该平台的配置-->
<SinaWeibo
AppKey="新浪微博的 AppKey"
AppSecret="新浪微博 AppSecret"
RedirectUrl="微博开放平台填写的授权回调页"/>
<QQ
AppId="QQ 的 AppId"
AppKey="QQ 的 AppKey"/>
<Wechat
AppId="微信的 AppId"
AppSecret="微信的 AppSectet"/>
<Facebook
AppId="facebook 的 appId"
AppName="facebook 后台填写的名称"
/>
<Twitter
ConsumerKey="twitter 的 ConsumerKey"
ConsumerSecret="twitter 的 ConsumerSecret"
/>
</DevInfor>
配置签名
在项目的 build.gradle 的 android 内部新增签名配置,例如:
signingConfigs {
debug {
storeFile file("jshare.jks") //签名文件路径
storePassword "sdkteam"
keyAlias "jshare"
keyPassword "sdkteam" //签名密码
}
release {
storeFile file("jshare.jks") //签名文件路径
storePassword "sdkteam"
keyAlias "jshare"
keyPassword "sdkteam" //签名密码
}
}
然后在项目的 build.gradle 的 buildTypes 使用签名配置,例如:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.debug
}
}
Application中初始化
public static void setDebugMode(boolean enable)
public static void init(Context context)