├── .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/#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 |
15 |
16 |
21 |
22 |
23 |
28 |
29 |
34 |
35 |
40 |
41 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | QQHelper
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: "config.gradle"
3 |
4 | buildscript {
5 | ext.kotlin_version = "1.8.0"
6 | repositories {
7 | google()
8 | mavenCentral()
9 | maven { url "https://jitpack.io" }
10 | // jcenter()
11 | }
12 | dependencies {
13 | classpath 'com.android.tools.build:gradle:7.3.1'
14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | // classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | google()
24 | mavenCentral()
25 | maven { url "https://jitpack.io" }
26 | // jcenter()
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | project.ext {
2 |
3 | android = [
4 | compileSdkVersion: 32,
5 | minSdkVersion : 16,
6 | targetSdkVersion : 32,
7 | versionCode : 1,
8 | versionName : "1.0.0"
9 | ]
10 |
11 | constants = [
12 | applicationId : "com.kongqw.qq",
13 | group : "com.github.kongqw",
14 | QQ_APP_ID : "xxx",
15 |
16 | SIGN_TORE_FILE_PATH: "../signatures/test.jks",
17 | SIGN_STORE_PASSWORD: "qqtest",
18 | SIGN_KEY_ALIAS : "qqtest",
19 | SIGN_KEY_PASSWORD : "qqtest"
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Mar 24 14:32:59 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/qqhelper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/qqhelper/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'kotlin-android'
4 | id 'maven-publish'
5 | }
6 |
7 | android {
8 | compileSdkVersion rootProject.ext.android["compileSdkVersion"]
9 |
10 | defaultConfig {
11 | minSdkVersion rootProject.ext.android["minSdkVersion"]
12 | targetSdkVersion rootProject.ext.android["targetSdkVersion"]
13 | versionCode rootProject.ext.android["versionCode"]
14 | versionName rootProject.ext.android["versionName"]
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | kotlinOptions {
30 | jvmTarget = '1.8'
31 | }
32 | }
33 |
34 | dependencies {
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
36 | implementation 'androidx.appcompat:appcompat:1.4.2'
37 |
38 | // https://wikinew.open.qq.com/index.html#/iwiki/864512506
39 | compileOnly files('libs/open_sdk_3.5.14.3_rc26220c_lite.jar')
40 | // compileOnly 'com.tencent.tauth:qqopensdk:3.52.0'
41 | }
42 |
43 | // Because the components are created only during the afterEvaluate phase, you must
44 | // configure your publications using the afterEvaluate() lifecycle method.
45 | afterEvaluate {
46 | publishing {
47 | publications {
48 | // Creates a Maven publication called "release".
49 | release(MavenPublication) {
50 | // Applies the component for the release build variant.
51 | from components.release
52 |
53 | groupId = 'com.github.kongqw'
54 | artifactId = 'QQHelper'
55 | version = '1.3.0'
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/qqhelper/libs/open_sdk_3.5.14.3_rc26220c_lite.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/qqhelper/libs/open_sdk_3.5.14.3_rc26220c_lite.jar
--------------------------------------------------------------------------------
/qqhelper/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 |
--------------------------------------------------------------------------------
/qqhelper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
19 |
20 |
24 |
25 |
31 |
32 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/QQHelper.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.os.Bundle
7 | import com.kongqw.qqhelper.login.QQLoginActivity
8 | import com.kongqw.qqhelper.login.listener.OnQQAuthLoginListener
9 | import com.kongqw.qqhelper.share.QQShareActivity
10 | import com.kongqw.qqhelper.share.listener.OnQQShareListener
11 | import com.kongqw.qqhelper.utils.AppUtils
12 | import com.tencent.connect.share.QQShare
13 | import com.tencent.connect.share.QzoneShare
14 | import com.tencent.tauth.Tencent
15 |
16 | class QQHelper {
17 |
18 | companion object {
19 | var IS_LOGGABLE: Boolean = false
20 |
21 | @Volatile
22 | private var instance: QQHelper? = null
23 |
24 | var mQQUiListener: OnQQShareListener? = null
25 | var mOnQQAuthLoginListener: OnQQAuthLoginListener? = null
26 |
27 | @JvmStatic
28 | fun init(isLoggable: Boolean, isPermissionGranted: Boolean = true) {
29 |
30 | IS_LOGGABLE = isLoggable
31 |
32 | Tencent.setIsPermissionGranted(isPermissionGranted)
33 | }
34 |
35 | @JvmStatic
36 | fun getInstance() = instance ?: synchronized(this) {
37 | instance ?: QQHelper().also { instance = it }
38 | }
39 | }
40 |
41 | /**
42 | * 分享图文
43 | */
44 | fun shareImageAndText(activity: Activity, title: String, summary: String, targetUrl: String, imageUrl: String, listener: OnQQShareListener) {
45 | mQQUiListener = listener
46 | // 检查QQ是否安装
47 | if(!AppUtils.isQQInstalled(activity)){
48 | mQQUiListener?.onNotInstall()
49 | return
50 | }
51 | val params = Bundle()
52 | params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT)
53 | params.putString(QQShare.SHARE_TO_QQ_TITLE, title)
54 | params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary)
55 | params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, targetUrl)
56 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imageUrl)
57 | params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE)
58 | QQShareActivity.share(activity, params)
59 | }
60 |
61 | /**
62 | * 分享纯图片
63 | */
64 | fun shareLocalImage(activity: Activity, localImageUrl: String, listener: OnQQShareListener) {
65 | mQQUiListener = listener
66 | // 检查QQ是否安装
67 | if(!AppUtils.isQQInstalled(activity)){
68 | mQQUiListener?.onNotInstall()
69 | return
70 | }
71 | val params = Bundle()
72 | params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE)
73 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, localImageUrl)
74 | params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE)
75 | QQShareActivity.share(activity, params)
76 | }
77 |
78 | /**
79 | * 分享到QQ空间
80 | */
81 | fun shareToQZone(activity: Activity, title: String, summary: String, targetUrl: String, imageUrl: String, listener: OnQQShareListener) {
82 | mQQUiListener = listener
83 | // 检查QQ是否安装
84 | if(!AppUtils.isQQInstalled(activity)){
85 | mQQUiListener?.onNotInstall()
86 | return
87 | }
88 | val params = Bundle()
89 | params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_IMAGE_TEXT)
90 | params.putString(QQShare.SHARE_TO_QQ_TITLE, title)
91 | params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary)
92 | params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, targetUrl)
93 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, imageUrl)
94 | params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN)
95 | QQShareActivity.share(activity, params)
96 | }
97 |
98 | /**
99 | * 自定义分享
100 | */
101 | fun customShare(activity: Activity, bundle: Bundle, listener: OnQQShareListener) {
102 | mQQUiListener = listener
103 | // 检查QQ是否安装
104 | if(!AppUtils.isQQInstalled(activity)){
105 | mQQUiListener?.onNotInstall()
106 | return
107 | }
108 | QQShareActivity.share(activity, bundle)
109 | }
110 |
111 | /**
112 | * 授权登录
113 | */
114 | fun authLogin(context: Context, listener: OnQQAuthLoginListener) {
115 | mOnQQAuthLoginListener = listener
116 | // 检查QQ是否安装
117 | if(!AppUtils.isQQInstalled(context)){
118 | mOnQQAuthLoginListener?.onNotInstall()
119 | return
120 | }
121 | context.startActivity(Intent(context, QQLoginActivity::class.java))
122 | }
123 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/login/QQLoginActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.login
2 |
3 | import android.content.Intent
4 | import androidx.appcompat.app.AppCompatActivity
5 | import android.os.Bundle
6 | import com.kongqw.qqhelper.QQHelper
7 | import com.kongqw.qqhelper.login.bean.QQLoginInfo
8 | import com.kongqw.qqhelper.utils.Logger
9 | import com.kongqw.qqhelper.utils.MetaUtil
10 | import com.tencent.connect.UserInfo
11 | import com.tencent.connect.common.Constants
12 | import com.tencent.tauth.IUiListener
13 | import com.tencent.tauth.Tencent
14 | import com.tencent.tauth.UiError
15 | import org.json.JSONObject
16 |
17 | internal class QQLoginActivity : AppCompatActivity() {
18 |
19 | companion object {
20 | private val TAG = QQLoginActivity::class.java.simpleName
21 | }
22 |
23 | private var mQQLoginInfo: QQLoginInfo? = null
24 | private val mOnLoginListener = object : IUiListener {
25 | /**
26 | * 登录成功
27 | */
28 | override fun onComplete(p0: Any?) {
29 | try {
30 | val jsonObject = p0 as JSONObject
31 |
32 | mQQLoginInfo?.access_token = if (jsonObject.has("access_token")) jsonObject.getString("access_token") else ""
33 | mQQLoginInfo?.expires_in = if (jsonObject.has("expires_in")) jsonObject.getString("expires_in") else ""
34 | mQQLoginInfo?.openid = if (jsonObject.has("openid")) jsonObject.getString("openid") else ""
35 |
36 | if (!mQQLoginInfo?.access_token.isNullOrEmpty() && !mQQLoginInfo?.expires_in.isNullOrEmpty()) {
37 | mTencent?.setAccessToken(mQQLoginInfo?.access_token, mQQLoginInfo?.expires_in)
38 | }
39 | if (!mQQLoginInfo?.openid.isNullOrEmpty()) {
40 | mTencent?.openId = mQQLoginInfo?.openid
41 | }
42 |
43 | val userInfo = UserInfo(applicationContext, mTencent?.qqToken)
44 | userInfo.getUserInfo(mOnGetUserInfoListener)
45 | } catch (e: Exception) {
46 | e.printStackTrace()
47 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginFail()
48 | }
49 | }
50 |
51 | /**
52 | * 登录取消
53 | */
54 | override fun onCancel() {
55 | Logger.i(TAG, "onQQAuthLoginCancel")
56 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginCancel()
57 | finish()
58 | }
59 |
60 | override fun onWarning(p0: Int) {
61 | Logger.i(TAG, "onWarning()")
62 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginCancel()
63 | finish()
64 | }
65 |
66 | /**
67 | * 登录失败
68 | */
69 | override fun onError(p0: UiError?) {
70 | Logger.i(TAG, "onQQAuthLoginError p0 = $p0")
71 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginError(p0?.errorCode, p0?.errorMessage, p0?.errorDetail)
72 | finish()
73 | }
74 | }
75 |
76 | private val mOnGetUserInfoListener = object : IUiListener {
77 | /**
78 | * 登录成功
79 | */
80 | override fun onComplete(p0: Any?) {
81 | try {
82 | Logger.i(TAG, "mOnGetUserInfoListener onComplete getUserInfo = $p0")
83 | val jsonObject = p0 as JSONObject
84 |
85 | mQQLoginInfo?.ret = jsonObject.getInt("ret")
86 | mQQLoginInfo?.msg = jsonObject.getString("msg")
87 | mQQLoginInfo?.is_lost = jsonObject.getInt("is_lost")
88 | mQQLoginInfo?.nickname = jsonObject.getString("nickname")
89 | mQQLoginInfo?.gender = jsonObject.getString("gender")
90 | mQQLoginInfo?.province = jsonObject.getString("province")
91 | mQQLoginInfo?.city = jsonObject.getString("city")
92 | mQQLoginInfo?.year = jsonObject.getString("year")
93 | mQQLoginInfo?.constellation = jsonObject.getString("constellation")
94 | mQQLoginInfo?.figureurl = jsonObject.getString("figureurl")
95 | mQQLoginInfo?.figureurl_1 = jsonObject.getString("figureurl_1")
96 | mQQLoginInfo?.figureurl_2 = jsonObject.getString("figureurl_2")
97 | mQQLoginInfo?.figureurl_qq = jsonObject.getString("figureurl_qq")
98 | mQQLoginInfo?.figureurl_qq_1 = jsonObject.getString("figureurl_qq_1")
99 | mQQLoginInfo?.figureurl_qq_2 = jsonObject.getString("figureurl_qq_2")
100 | mQQLoginInfo?.figureurl_type = jsonObject.getString("figureurl_type")
101 | mQQLoginInfo?.is_yellow_vip = jsonObject.getString("is_yellow_vip")
102 | mQQLoginInfo?.vip = jsonObject.getString("vip")
103 | mQQLoginInfo?.yellow_vip_level = jsonObject.getString("yellow_vip_level")
104 | mQQLoginInfo?.level = jsonObject.getString("level")
105 | mQQLoginInfo?.is_yellow_year_vip = jsonObject.getString("is_yellow_year_vip")
106 |
107 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginSuccess(mQQLoginInfo)
108 | } catch (e: Exception) {
109 | e.printStackTrace()
110 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginFail()
111 | }
112 | finish()
113 | }
114 |
115 | /**
116 | * 登录取消
117 | */
118 | override fun onCancel() {
119 | Logger.i(TAG, "onQQAuthLoginCancel")
120 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginCancel()
121 | finish()
122 | }
123 |
124 | /**
125 | * 警告
126 | */
127 | override fun onWarning(p0: Int) {
128 | Logger.i(TAG, "onWarning($p0)")
129 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginWarning(p0)
130 | finish()
131 | }
132 |
133 | /**
134 | * 登录失败
135 | */
136 | override fun onError(p0: UiError?) {
137 | Logger.i(TAG, "onQQAuthLoginError p0 = $p0")
138 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginError(p0?.errorCode, p0?.errorMessage, p0?.errorDetail)
139 | finish()
140 | }
141 | }
142 |
143 |
144 | private var mTencent: Tencent? = null
145 |
146 | override fun onCreate(savedInstanceState: Bundle?) {
147 | super.onCreate(savedInstanceState)
148 |
149 | mQQLoginInfo = QQLoginInfo()
150 |
151 | val qqAppId = MetaUtil.getQQAppId(applicationContext)
152 |
153 | mTencent = Tencent.createInstance(qqAppId, applicationContext)
154 | Logger.i(TAG, "QQAppId = $qqAppId")
155 |
156 | val login = mTencent?.login(this, "all", mOnLoginListener)
157 | Logger.i(TAG, "login = $login")
158 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginStart()
159 | }
160 |
161 | override fun onDestroy() {
162 | QQHelper.mOnQQAuthLoginListener = null
163 | super.onDestroy()
164 | }
165 |
166 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
167 | Logger.i(TAG, "onActivityResult requestCode = $requestCode resultCode = $resultCode")
168 | if (resultCode != Constants.ACTIVITY_OK) {
169 | // 取消了
170 | super.onActivityResult(requestCode, resultCode, data)
171 | QQHelper.mOnQQAuthLoginListener?.onQQAuthLoginCancel()
172 | finish()
173 | return
174 | }
175 | if (requestCode == Constants.REQUEST_LOGIN && resultCode == Constants.ACTIVITY_OK) {
176 | Tencent.handleResultData(data, mOnLoginListener)
177 | }
178 | super.onActivityResult(requestCode, resultCode, data)
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/login/bean/QQLoginInfo.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.login.bean
2 |
3 | import java.io.Serializable
4 |
5 | class QQLoginInfo : Serializable {
6 |
7 | var ret: Int? = null
8 | var msg: String? = null
9 |
10 | var openid: String? = null
11 | var access_token: String? = null
12 | var pay_token: String? = null
13 | var expires_in: String? = null
14 | var pf: String? = null
15 | var pfkey: String? = null
16 | var login_cost: Int? = null
17 | var query_authority_cost: Int? = null
18 | var authority_cost: Int? = null
19 |
20 | var is_lost: Int? = null
21 | var nickname: String? = null
22 | var gender: String? = null
23 | var province: String? = null
24 | var city: String? = null
25 | var year: String? = null
26 | var constellation: String? = null
27 | var figureurl: String? = null
28 | var figureurl_1: String? = null
29 | var figureurl_2: String? = null
30 | var figureurl_qq: String? = null
31 | var figureurl_qq_1: String? = null
32 | var figureurl_qq_2: String? = null
33 | var figureurl_type: String? = null
34 | var is_yellow_vip: String? = null
35 | var vip: String? = null
36 | var yellow_vip_level: String? = null
37 | var level: String? = null
38 | var is_yellow_year_vip: String? = null
39 |
40 | override fun toString(): String {
41 | return "QQLoginInfo(ret=$ret, msg=$msg, openid=$openid, access_token=$access_token, pay_token=$pay_token, expires_in=$expires_in, pf=$pf, pfkey=$pfkey, login_cost=$login_cost, query_authority_cost=$query_authority_cost, authority_cost=$authority_cost, is_lost=$is_lost, nickname=$nickname, gender=$gender, province=$province, city=$city, year=$year, constellation=$constellation, figureurl=$figureurl, figureurl_1=$figureurl_1, figureurl_2=$figureurl_2, figureurl_qq=$figureurl_qq, figureurl_qq_1=$figureurl_qq_1, figureurl_qq_2=$figureurl_qq_2, figureurl_type=$figureurl_type, is_yellow_vip=$is_yellow_vip, vip=$vip, yellow_vip_level=$yellow_vip_level, level=$level, is_yellow_year_vip=$is_yellow_year_vip)"
42 | }
43 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/login/listener/OnQQAuthLoginListener.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.login.listener
2 |
3 | import com.kongqw.qqhelper.login.bean.QQLoginInfo
4 |
5 | interface OnQQAuthLoginListener {
6 | fun onQQAuthLoginStart()
7 | fun onQQAuthLoginSuccess(qqLoginInfo: QQLoginInfo?)
8 | fun onQQAuthLoginCancel()
9 | fun onQQAuthLoginFail()
10 | fun onQQAuthLoginError(errorCode: Int?, errorMessage: String?, errorDetail: String?)
11 | fun onQQAuthLoginWarning(code: Int)
12 | fun onNotInstall()
13 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/share/QQShareActivity.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.share
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import androidx.appcompat.app.AppCompatActivity
6 | import android.os.Bundle
7 | import com.kongqw.qqhelper.QQHelper
8 | import com.kongqw.qqhelper.utils.Logger
9 | import com.kongqw.qqhelper.utils.MetaUtil
10 | import com.tencent.tauth.IUiListener
11 | import com.tencent.tauth.Tencent
12 | import com.tencent.tauth.UiError
13 |
14 | internal class QQShareActivity : AppCompatActivity(), IUiListener {
15 |
16 | private var mTencent: Tencent? = null
17 |
18 | companion object {
19 | private val TAG = QQShareActivity::class.java.simpleName
20 | private const val EXTRA_SHARE_PARAMS = "EXTRA_SHARE_PARAMS"
21 |
22 | fun share(context: Context, bundle: Bundle) {
23 | context.startActivity(Intent(context, QQShareActivity::class.java).putExtra(EXTRA_SHARE_PARAMS, bundle))
24 | }
25 | }
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | mTencent = Tencent.createInstance(MetaUtil.getQQAppId(applicationContext), applicationContext)
30 |
31 | val params = intent.getBundleExtra(EXTRA_SHARE_PARAMS)
32 | mTencent?.shareToQQ(this, params, this)
33 |
34 | QQHelper.mQQUiListener?.onQQShareStart()
35 | }
36 |
37 | override fun onDestroy() {
38 | QQHelper.mQQUiListener = null
39 | super.onDestroy()
40 | }
41 |
42 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
43 | Logger.i(TAG, "onActivityResult($requestCode, $resultCode, $data)")
44 | super.onActivityResult(requestCode, resultCode, data)
45 | Tencent.onActivityResultData(requestCode, resultCode, data, this)
46 | }
47 |
48 | /**
49 | * 分享完成
50 | */
51 | override fun onComplete(p0: Any?) {
52 | Logger.i(TAG, "分享完成 onComplete($p0)")
53 | QQHelper.mQQUiListener?.onQQShareComplete(p0)
54 | finish()
55 | }
56 |
57 | /**
58 | * 分享取消
59 | */
60 | override fun onCancel() {
61 | Logger.i(TAG, "分享取消 onCancel()")
62 | QQHelper.mQQUiListener?.onQQShareCancel()
63 | finish()
64 | }
65 |
66 | /**
67 | * 分享警告
68 | */
69 | override fun onWarning(p0: Int) {
70 | Logger.i(TAG, "分享异常 onWarning($p0)")
71 | QQHelper.mQQUiListener?.onQQShareWarning(p0)
72 | finish()
73 | }
74 |
75 | /**
76 | * 分享异常
77 | */
78 | override fun onError(p0: UiError?) {
79 | Logger.i(TAG, "分享异常 onError($p0)")
80 | QQHelper.mQQUiListener?.onQQShareError(p0?.errorCode, p0?.errorMessage, p0?.errorDetail)
81 | finish()
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/share/listener/OnQQShareListener.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.share.listener
2 |
3 | interface OnQQShareListener {
4 |
5 | fun onQQShareStart()
6 |
7 | fun onQQShareComplete(p0: Any?)
8 |
9 | fun onQQShareCancel()
10 |
11 | fun onQQShareError(errorCode: Int?, errorMessage: String?, errorDetail: String?)
12 |
13 | fun onQQShareWarning(code: Int)
14 |
15 | fun onNotInstall()
16 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/utils/AppUtils.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.utils
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 |
6 | internal object AppUtils {
7 |
8 | /**
9 | * 是否安装了QQ
10 | */
11 | @SuppressLint("QueryPermissionsNeeded")
12 | @JvmStatic
13 | fun isQQInstalled(context: Context): Boolean {
14 | try {
15 | context.applicationContext.packageManager.getInstalledPackages(0).forEach { packageInfo ->
16 | if ("com.tencent.mobileqq" == packageInfo.packageName) {
17 | return true
18 | }
19 | }
20 | } catch (e: Exception) {
21 | e.printStackTrace()
22 | }
23 | return false
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/utils/BitmapUtil.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.utils
2 |
3 | import android.graphics.Bitmap
4 | import java.io.ByteArrayOutputStream
5 |
6 | internal object BitmapUtil {
7 |
8 | /**
9 | * Bitmap 转 ByteArray
10 | */
11 | fun bitmapToByteArray(bmp: Bitmap, needRecycle: Boolean): ByteArray? {
12 | val output = ByteArrayOutputStream()
13 | return try {
14 | bmp.compress(Bitmap.CompressFormat.PNG, 100, output)
15 | if (needRecycle) {
16 | bmp.recycle()
17 | }
18 | output.toByteArray()
19 | } catch (e: Exception) {
20 | e.printStackTrace()
21 | null
22 | } finally {
23 | output.close()
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/utils/Logger.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.utils
2 |
3 | import android.util.Log
4 | import com.kongqw.qqhelper.QQHelper
5 |
6 | internal object Logger {
7 |
8 | fun i(tag: String, log: String?) {
9 | if (QQHelper.IS_LOGGABLE) {
10 | Log.d(tag, log ?: "")
11 | }
12 | }
13 |
14 | // fun d(log: String?) {
15 | // if (QQHelper.IS_LOGGABLE) {
16 | // Log.d("Logger", log ?: "")
17 | // }
18 | // }
19 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/java/com/kongqw/qqhelper/utils/MetaUtil.kt:
--------------------------------------------------------------------------------
1 | package com.kongqw.qqhelper.utils
2 |
3 | import android.content.Context
4 | import android.content.pm.PackageManager
5 |
6 | internal object MetaUtil {
7 |
8 | /**
9 | * 读取AppMetaData信息
10 | */
11 | private fun getAppMetaData(context: Context, key: String): String? {
12 | if (key.isEmpty()) {
13 | return null
14 | }
15 | return try {
16 | context.packageManager?.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
17 | ?.metaData?.get(key)?.toString()
18 | } catch (e: PackageManager.NameNotFoundException) {
19 | e.printStackTrace()
20 | null
21 | }
22 | }
23 |
24 | /**
25 | * 获取QQ APP ID
26 | */
27 | fun getQQAppId(context: Context): String? {
28 | return getAppMetaData(context, "qq_app_id")
29 | }
30 | }
--------------------------------------------------------------------------------
/qqhelper/src/main/res/anim/translucent_enter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
--------------------------------------------------------------------------------
/qqhelper/src/main/res/anim/translucent_exit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/qqhelper/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | qqhelper
3 |
4 |
--------------------------------------------------------------------------------
/qqhelper/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':qqhelper'
2 |
--------------------------------------------------------------------------------
/signatures/test.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kongqw/QQHelper/d2a4c6abb87f0d3dd925a88bac76bb425497d2bc/signatures/test.jks
--------------------------------------------------------------------------------