├── .gitignore ├── .idea └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ └── open_sdk_3.5.14.3_rc26220c_lite.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kongqw │ │ └── qq │ │ ├── MainActivity.kt │ │ └── MyApplication.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── config.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── qqhelper ├── .gitignore ├── build.gradle ├── libs │ └── open_sdk_3.5.14.3_rc26220c_lite.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── kongqw │ │ └── qqhelper │ │ ├── QQHelper.kt │ │ ├── login │ │ ├── QQLoginActivity.kt │ │ ├── bean │ │ │ └── QQLoginInfo.kt │ │ └── listener │ │ │ └── OnQQAuthLoginListener.kt │ │ ├── share │ │ ├── QQShareActivity.kt │ │ └── listener │ │ │ └── OnQQShareListener.kt │ │ └── utils │ │ ├── AppUtils.kt │ │ ├── BitmapUtil.kt │ │ ├── Logger.kt │ │ └── MetaUtil.kt │ └── res │ ├── anim │ ├── translucent_enter.xml │ └── translucent_exit.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── settings.gradle └── signatures └── test.jks /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QQ开放平台功能封装 2 | 3 | [![](https://jitpack.io/v/kongqw/QQHelper.svg)](https://jitpack.io/#kongqw/QQHelper) 4 | 5 | To get a Git project into your build: 6 | 7 | Step 1. Add the JitPack repository to your build file 8 | 9 | Add it in your root build.gradle at the end of repositories: 10 | 11 | ``` gradle 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | 20 | Step 2. Add the dependency 21 | 22 | ``` gradle 23 | dependencies { 24 | implementation 'com.github.kongqw:QQHelper:1.3.1' 25 | } 26 | ``` 27 | 28 | 自行[下载](https://wiki.connect.qq.com/sdk%e4%b8%8b%e8%bd%bd)jar包,引入到项目中,Library不再将打入jar包。 29 | 30 | ### Gradle 配置 QQ_APP_ID 31 | 32 | ``` gradle 33 | android { 34 | …… 35 | defaultConfig { 36 | …… 37 | manifestPlaceholders = [ 38 | QQ_APP_ID : '你申请的appid' 39 | ] 40 | …… 41 | } 42 | …… 43 | } 44 | ``` 45 | 46 | ## 初始化(非必要) 47 | 48 | ``` kotlin 49 | QQHelper.init(true, 是否已经授权) 50 | ``` 51 | 关系到上架后的隐私问题,详见 [Tencent.setIsPermissionGranted](https://wiki.connect.qq.com/qq%e7%99%bb%e5%bd%95) 52 | 53 | ## QQ分享 54 | 55 | ### 分享图文链接 56 | 57 | ``` kotlin 58 | QQHelper.getInstance().shareImageAndText(`activity`, `标题`, `摘要`, `链接`, `缩略图`, `监听接口`) 59 | ``` 60 | 61 | ### 分享图片 62 | 63 | ``` kotlin 64 | QQHelper.getInstance().shareLocalImage(`activity`, `本地图片地址`, `监听接口`) 65 | ``` 66 | 67 | ### 分享到QQ空间 68 | 69 | ``` kotlin 70 | QQHelper.getInstance().shareToQZone(`activity`, `标题`, `摘要`, `链接`, `缩略图`, `监听接口`) 71 | ``` 72 | 73 | ### 自定义分享 74 | 75 | `自定义Bundle`详见 [API调用说明](http://wiki.open.qq.com/wiki/mobile/API%E8%B0%83%E7%94%A8%E8%AF%B4%E6%98%8E#1.13_.E5.88.86.E4.BA.AB.E6.B6.88.E6.81.A) 76 | 77 | ``` kotlin 78 | QQHelper.getInstance().customShare(`activity`, `自定义Bundle`, `监听接口`) 79 | ``` 80 | 81 | ### 监听接口 82 | 83 | ``` kotlin 84 | interface OnQQShareListener { 85 | fun onQQShareStart() 86 | fun onQQShareComplete(p0: Any?) 87 | fun onQQShareCancel() 88 | fun onQQShareError(errorCode: Int?, errorMessage: String?, errorDetail: String?) 89 | fun onNotInstall() 90 | } 91 | ``` 92 | 93 | ## 授权登录 94 | 95 | ``` kotlin 96 | QQHelper.getInstance().authLogin(`Activity Context`, `监听接口`) 97 | ``` 98 | 99 | ### 监听接口 100 | 101 | ``` kotlin 102 | interface OnQQAuthLoginListener { 103 | fun onQQAuthLoginStart() 104 | fun onQQAuthLoginSuccess(qqLoginInfo: QQLoginInfo?) 105 | fun onQQAuthLoginCancel() 106 | fun onQQAuthLoginFail() 107 | fun onQQAuthLoginError(errorCode: Int?, errorMessage: String?, errorDetail: String?) 108 | fun onNotInstall() 109 | } 110 | ``` -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | def BuildConfig = rootProject.ext.android 7 | def BuildConstants = rootProject.ext.constants 8 | 9 | android { 10 | compileSdkVersion BuildConfig["compileSdkVersion"] 11 | 12 | defaultConfig { 13 | applicationId BuildConstants["applicationId"] 14 | minSdkVersion BuildConfig["minSdkVersion"] 15 | targetSdkVersion BuildConfig["targetSdkVersion"] 16 | versionCode BuildConfig["versionCode"] 17 | versionName BuildConfig["versionName"] 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | 20 | manifestPlaceholders = [ 21 | QQ_APP_ID: BuildConstants["QQ_APP_ID"] 22 | ] 23 | 24 | signingConfigs { 25 | sign { 26 | storeFile file(BuildConstants["SIGN_TORE_FILE_PATH"]) 27 | storePassword BuildConstants["SIGN_STORE_PASSWORD"] 28 | keyAlias = BuildConstants["SIGN_KEY_ALIAS"] 29 | keyPassword BuildConstants["SIGN_KEY_PASSWORD"] 30 | } 31 | debug.initWith(sign) 32 | } 33 | } 34 | buildTypes { 35 | release { 36 | minifyEnabled true 37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 38 | signingConfig signingConfigs.sign 39 | } 40 | debug { 41 | minifyEnabled false 42 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 43 | signingConfig signingConfigs.sign 44 | } 45 | } 46 | 47 | compileOptions { 48 | sourceCompatibility JavaVersion.VERSION_1_8 49 | targetCompatibility JavaVersion.VERSION_1_8 50 | } 51 | kotlinOptions { 52 | jvmTarget = '1.8' 53 | } 54 | } 55 | 56 | dependencies { 57 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 58 | implementation fileTree(dir: 'libs', include: ['*.jar']) 59 | implementation 'androidx.appcompat:appcompat:1.4.2' 60 | implementation 'androidx.core:core-ktx:1.8.0' 61 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 62 | testImplementation 'junit:junit:4.13.2' 63 | androidTestImplementation 'androidx.test:runner:1.4.0' 64 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 65 | implementation project(path: ':qqhelper') 66 | 67 | implementation files('libs/open_sdk_3.5.14.3_rc26220c_lite.jar') 68 | // implementation 'com.tencent.tauth:qqopensdk:3.52.0' 69 | } 70 | -------------------------------------------------------------------------------- /app/libs/open_sdk_3.5.14.3_rc26220c_lite.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/libs/open_sdk_3.5.14.3_rc26220c_lite.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/kongqw/qq/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.kongqw.qq 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.util.Log 6 | import android.view.View 7 | import android.widget.Toast 8 | import com.kongqw.qqhelper.QQHelper 9 | import com.kongqw.qqhelper.login.bean.QQLoginInfo 10 | import com.kongqw.qqhelper.login.listener.OnQQAuthLoginListener 11 | import com.kongqw.qqhelper.share.listener.OnQQShareListener 12 | import com.tencent.connect.share.QQShare 13 | 14 | class MainActivity : AppCompatActivity(), OnQQShareListener, OnQQAuthLoginListener { 15 | 16 | private val images = arrayOf( 17 | "https://img.xsnvshen.co/album/28318/39866/000.jpg", 18 | "https://img.xsnvshen.co/album/28176/36862/000.jpg", 19 | "https://img.xsnvshen.co/album/28176/39801/002.jpg", 20 | "https://img.xsnvshen.co/album/28176/39801/000.jpg" 21 | ) 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setContentView(R.layout.activity_main) 26 | } 27 | 28 | /** 29 | * 分享图文 30 | */ 31 | fun onShareImageAndText(view: View) { 32 | 33 | QQHelper.getInstance().shareImageAndText( 34 | this, 35 | "干活集中营", 36 | "都是干货,还有妹子图哦", 37 | "http://gank.io", 38 | images.random(), 39 | this 40 | ) 41 | } 42 | 43 | /** 44 | * 分享图片 45 | */ 46 | fun onShareLocalImage(view: View) { 47 | QQHelper.getInstance().shareLocalImage( 48 | this, 49 | "/storage/emulated/0/DCIM/Camera/IMG_20190602_220325.jpg", 50 | this 51 | ) 52 | } 53 | 54 | /** 55 | * 分享到QQ空间 56 | */ 57 | fun onShareToQZone(view: View) { 58 | QQHelper.getInstance().shareToQZone( 59 | this, 60 | "干活集中营", 61 | "都是干货,还有妹子图哦", 62 | "http://gank.io", 63 | images.random(), 64 | this 65 | ) 66 | } 67 | 68 | /** 69 | * 分享音乐【自定义】 70 | */ 71 | fun onCustomShareMusic(view: View) { 72 | val params = Bundle().apply { 73 | putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_AUDIO) 74 | putString(QQShare.SHARE_TO_QQ_TITLE, "干活集中营") 75 | putString(QQShare.SHARE_TO_QQ_SUMMARY, "都是干货,还有妹子图哦") 76 | putString(QQShare.SHARE_TO_QQ_TARGET_URL, "http://gank.io") 77 | putString(QQShare.SHARE_TO_QQ_IMAGE_URL, images.random()) 78 | putString( 79 | QQShare.SHARE_TO_QQ_AUDIO_URL, 80 | "http://m10.music.126.net/20190402151400/39f1d995f4b2d48efa312d1ecb71550f/ymusic/363b/72ef/7661/0b373b6cdfc54e3022ef436c3ad58ec3.mp3" 81 | ) 82 | putString(QQShare.SHARE_TO_QQ_APP_NAME, String.format("%s%s", getString(R.string.app_name), "")) 83 | putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE) 84 | } 85 | QQHelper.getInstance().customShare(this, params, this) 86 | } 87 | 88 | /** 89 | * 分享APP【自定义】 90 | */ 91 | fun onCustomShareApp(view: View) { 92 | val params = Bundle().apply { 93 | // putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_APP) 94 | putString(QQShare.SHARE_TO_QQ_TITLE, "干活集中营") 95 | putString(QQShare.SHARE_TO_QQ_SUMMARY, "都是干货,还有妹子图哦") 96 | putString(QQShare.SHARE_TO_QQ_IMAGE_URL, images.random()) 97 | putString(QQShare.SHARE_TO_QQ_APP_NAME, String.format("%s%s", getString(R.string.app_name), "")) 98 | putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE) 99 | } 100 | QQHelper.getInstance().customShare(this, params, this) 101 | } 102 | 103 | /** 104 | * 授权登录 105 | */ 106 | fun onAuthLogin(view: View) { 107 | QQHelper.getInstance().authLogin(this, this) 108 | } 109 | 110 | 111 | 112 | override fun onQQAuthLoginStart() { 113 | Toast.makeText(applicationContext, "开始登录", Toast.LENGTH_SHORT).show() 114 | } 115 | 116 | override fun onQQAuthLoginSuccess(qqLoginInfo: QQLoginInfo?) { 117 | Log.i("MainActivity", "qqLoginInfo = $qqLoginInfo") 118 | Toast.makeText(applicationContext, "登录成功", Toast.LENGTH_SHORT).show() 119 | } 120 | 121 | override fun onQQAuthLoginCancel() { 122 | Toast.makeText(applicationContext, "取消登录", Toast.LENGTH_SHORT).show() 123 | } 124 | 125 | override fun onQQAuthLoginFail() { 126 | Toast.makeText(applicationContext, "登录失败", Toast.LENGTH_SHORT).show() 127 | } 128 | 129 | override fun onQQAuthLoginError(errorCode: Int?, errorMessage: String?, errorDetail: String?) { 130 | Toast.makeText(applicationContext, "登录异常", Toast.LENGTH_SHORT).show() 131 | } 132 | 133 | override fun onQQAuthLoginWarning(code: Int) { 134 | Toast.makeText(applicationContext, "登录警告 code = $code", Toast.LENGTH_SHORT).show() 135 | } 136 | 137 | override fun onQQShareStart() { 138 | Toast.makeText(applicationContext, "开始分享", Toast.LENGTH_SHORT).show() 139 | } 140 | 141 | override fun onQQShareComplete(p0: Any?) { 142 | Toast.makeText(applicationContext, "分享成功", Toast.LENGTH_SHORT).show() 143 | } 144 | 145 | override fun onQQShareCancel() { 146 | Toast.makeText(applicationContext, "取消分享", Toast.LENGTH_SHORT).show() 147 | } 148 | 149 | override fun onQQShareError(errorCode: Int?, errorMessage: String?, errorDetail: String?) { 150 | Log.i("MainActivity", "onQQShareError($errorCode, $errorMessage, $errorDetail)") 151 | Toast.makeText(applicationContext, "分享失败", Toast.LENGTH_SHORT).show() 152 | } 153 | 154 | override fun onQQShareWarning(code: Int) { 155 | // Toast.makeText(applicationContext, "分享警告 code = $code", Toast.LENGTH_SHORT).show() 156 | } 157 | 158 | override fun onNotInstall() { 159 | Toast.makeText(applicationContext, "QQ未安装", Toast.LENGTH_SHORT).show() 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /app/src/main/java/com/kongqw/qq/MyApplication.kt: -------------------------------------------------------------------------------- 1 | package com.kongqw.qq 2 | 3 | import android.app.Application 4 | import com.kongqw.qqhelper.QQHelper 5 | 6 | class MyApplication : Application() { 7 | 8 | override fun onCreate() { 9 | super.onCreate() 10 | 11 | // init Library 12 | // WeChatLoginLibrary(this).init(BuildConfig.DEBUG) 13 | 14 | QQHelper.init(true) 15 | } 16 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 |