提交 1d96b609 作者: 钱宇

modify:聚合sdk文档修改:回调改为callback。

上级 8d8acf2f
plugins {
plugins {
......@@ -10,7 +10,7 @@ android {
defaultConfig {
applicationId = "com.zwgame.test.gamecenterdemo"
minSdk = 30
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
......
package com.zwgame.test.gamecenterdemo
package com.zwgame.test.gamecenterdemo
package com.zwgame.test.gamecenterdemo
import android.content.res.AssetManager
import android.content.res.Resources
import android.os.Bundle
import android.util.Log
import android.widget.TextView
......@@ -18,6 +16,8 @@ class MainActivity : AppCompatActivity() {
private lateinit var statusText: TextView
private var busy = false
private val TAG = "gamecenter_demo"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
......@@ -50,37 +50,49 @@ class MainActivity : AppCompatActivity() {
private fun onInitClick() = guardBusy {
statusText.setText(R.string.status_init_clicked)
ZySdk.sdkInit(this) { result ->
releaseBusy()
if (isFinishing) return@sdkInit
Log.i(TAG, "sdkInit result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
val channelCode = obj.optString("channelCode")
Log.i(TAG, "init 成功,当前渠道:$channelCode")
} else {
Log.w(TAG, "init 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}")
ZySdk.sdkInit(this, true, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
Log.i(TAG, "sdkInit result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
val channelCode = obj.optString("channelCode")
Log.i(TAG, "init 成功,当前渠道:$channelCode")
} else {
Log.w(
TAG,
"init 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
}
}
}
})
}
private fun onLoginClick() = guardBusy {
statusText.setText(R.string.status_login_clicked)
ZySdk.sdkLogin(this) { result ->
releaseBusy()
if (isFinishing) return@sdkLogin
Log.i(TAG, "sdkLogin result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (!success) {
Log.w(TAG, "login 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}")
ZySdk.sdkLogin(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
Log.i(TAG, "sdkLogin result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (!success) {
Log.w(
TAG,
"login 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
}
}
}
})
}
private fun onReportUserClick() = guardBusy {
......@@ -107,28 +119,39 @@ class MainActivity : AppCompatActivity() {
put("ext", "")
put("playerId", "1")
}.toString()
ZySdk.sdkReportRole(this, roleJson) { result ->
releaseBusy()
if (isFinishing) return@sdkReportRole
Log.i(TAG, "sdkReportRole result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "reportRole 成功")
} else {
Log.w(TAG, "reportRole 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}")
ZySdk.sdkReportRole(this, roleJson, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
Log.i(TAG, "sdkReportRole result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "reportRole 成功")
} else {
Log.w(
TAG,
"reportRole 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${
obj.optInt("errorCode")
}"
)
}
}
}
})
}
private fun onUpgradeClick() = guardBusy {
statusText.setText(R.string.status_upgrade_clicked)
ZySdk.sdkUpdate(this) { result ->
releaseBusy()
if (isFinishing) return@sdkUpdate
}
ZySdk.sdkUpdate(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
}
})
}
private fun onPayClick() = guardBusy {
......@@ -158,55 +181,76 @@ class MainActivity : AppCompatActivity() {
put("attach", "sdk2_mock_attach")
put("callbackUrl", Constant.Order.CALLBACK_OPPO)
}.toString()
ZySdk.sdkPay(this, payJson) { result ->
releaseBusy()
if (isFinishing) return@sdkPay
Log.i(TAG, "sdkPay result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (!success) {
Log.w(TAG, "pay 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}")
ZySdk.sdkPay(this, payJson, callback = object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
Log.i(TAG, "sdkPay result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (!success) {
Log.w(
TAG,
"pay 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
}
}
}
})
}
private fun onShowFloatClick() {
statusText.setText(R.string.status_show_float_clicked)
ZySdk.sdkShowFloat(this) { }
ZySdk.sdkShowFloat(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
})
}
private fun onHideFloatClick() {
statusText.setText(R.string.status_hide_float_clicked)
ZySdk.sdkHideFloat(this) { }
ZySdk.sdkHideFloat(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
})
}
private fun onExitClick() = guardBusy {
statusText.setText(R.string.status_exit_clicked)
ZySdk.sdkExit(this) { result ->
releaseBusy()
if (isFinishing) return@sdkExit
Log.i(TAG, "sdkExit result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "用户在联运退出引导中确认退出")
save()
ZySdk.sdkExit(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy()
if (isFinishing)
return
Log.i(TAG, "sdkExit result=$result")
statusText.text = result
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "用户在联运退出引导中确认退出")
save()
// exitProcess(0)
} else {
Log.i(TAG, "退出取消或失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}")
} else {
Log.i(
TAG,
"退出取消或失败 errorMsg=${obj.optString("errorMsg")} errorCode=${
obj.optInt("errorCode")
}"
)
}
}
}
})
}
private fun save() {
//保存进度
}
private companion object {
private const val TAG = "MainActivity"
}
......
# Game Center SDK 接入说明V1.0.0.0
# Game Center SDK 接入说明V1.0.0.0
......@@ -71,33 +71,33 @@
```kotlin
dependencyResolutionManagement {
repositories {
// sdk仓库
maven {
url = uri("http://nexus.zwwlkj01.top/repository/android-advertisement")
isAllowInsecureProtocol = true
credentials {
username = ""
password = ""
}
repositories {
// sdk仓库
maven {
url = uri("http://nexus.zwwlkj01.top/repository/android-advertisement")
isAllowInsecureProtocol = true
credentials {
username = ""
password = ""
}
}
// 巨量媒体
maven {
url =uri("https://artifact.bytedance.com/repository/Volcengine/")
}
// 建议保留
google()
mavenCentral()
// 打华为包时保留
maven {
url = uri("https://developer.huawei.com/repo/")
}
}
// 巨量媒体
maven {
url =uri("https://artifact.bytedance.com/repository/Volcengine/")
}
// 建议保留
google()
mavenCentral()
// 打华为包时保留
maven {
url = uri("https://developer.huawei.com/repo/")
}
}
}
```
......@@ -125,17 +125,17 @@ implementation("com.zw.game.center:gameCenter:1.0.0.0")
工程级 **`build.gradle.kts`** 中,加入
```kotlin
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:8.13.2")
classpath("com.huawei.agconnect:agcp:1.9.5.302")
}
dependencies {
classpath("com.android.tools.build:gradle:8.13.2")
classpath("com.huawei.agconnect:agcp:1.9.5.302")
}
}
```
app模块下添加agc插件
```kotlin
plugins {
id("com.huawei.agconnect")
id("com.huawei.agconnect")
}
```
......@@ -149,27 +149,30 @@ plugins {
在Activity进行初始化,且只初始化一次。
```kotlin
ZySdk.sdkInit(activity) { result ->
// 初始化结果:成功/失败信息与错误码等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
val channelCode = obj.optString("channelCode")
Log.i(TAG, "init 成功,当前渠道:$channelCode")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
ZySdk.sdkInit(activity, true, object : ZySdkCallback {
override fun onResult(result: String) {
// 初始化结果:成功/失败信息与错误码等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
val channelCode = obj.optString("channelCode")
Log.i(TAG, "init 成功,当前渠道:$channelCode")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:----------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 初始化结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:--------------------------:|:-------------:|:--------------------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `showLoginBackgroundImage` | Boolean | 为 true 时,登录等界面会套用在 SDK 中配置的登录背景图 |
| `callback` | ZySdkCallback | 初始化结果回调(JsonObject字符串) |
**回参**
......@@ -198,27 +201,29 @@ ZySdk.sdkInit(activity) { result ->
用于拉起渠道账号体系或聚合登录流程,成功返回参数请传给游戏服完成鉴权与建号。
```kotlin
ZySdk.sdkLogin(activity) { result ->
// id、token等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
//val member_id = obj.optString("member_id")
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
ZySdk.sdkLogin(activity, object : ZySdkCallback {
override fun onResult(result: String) {
// id、token等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
//val member_id = obj.optString("member_id")
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:---------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 登录结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:---------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `callback` | ZySdkCallback | 登录结果回调(JsonObject字符串) |
**回参**
......@@ -287,26 +292,28 @@ ZySdk.sdkLogin(activity) { result ->
在登录成功、切换角色等操作后需进行角色信息上报。
```kotlin
ZySdk.sdkReportRole(activity, roleJson) { result ->
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
ZySdk.sdkReportRole(activity, roleJson, object : ZySdkCallback {
override fun onResult(result: String) {
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `roleJson` | String | 角色信息Json字符串 |
| `result` | String | 结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `roleJson` | String | 角色信息Json字符串 |
| `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**roleJson参数如下:**
......@@ -355,29 +362,31 @@ ZySdk.sdkReportRole(activity, roleJson) { result ->
### 6. SDK支付
```kotlin
ZySdk.sdkPay(activity, payJson) { result ->
// 购买数据、签名等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
//val purchaseData = obj.optString("purchaseData")
//val purchaseDataSignature = obj.optString("purchaseDataSignature")
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
ZySdk.sdkPay(activity, payJson, object : ZySdkCallback {
override fun onResult(result: String) {
// 购买数据、签名等
val obj = JSONObject(result)
val success = obj.optBoolean("success")
if (success) {
//val purchaseData = obj.optString("purchaseData")
//val purchaseDataSignature = obj.optString("purchaseDataSignature")
Log.i(TAG, "成功")
} else {
val errorMsg = obj.optString("errorMsg")
val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `payJson` | String | 支付信息Json字符串 |
| `result` | String | 结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `payJson` | String | 支付信息Json字符串 |
| `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**payJson参数如下:**
......@@ -450,22 +459,24 @@ ZySdk.sdkPay(activity, payJson) { result ->
在用户点击「退出游戏」等入口时调用,在回调中可实现保存进度、退出游戏等操作。
```kotlin
ZySdk.sdkExit(activity) { result ->
if (result.optBoolean("success")) {
save() //保存进度
exitProcess(0) // 结束进程
} else {
// 用户取消,或失败时查看 errorMsg / errorCode
}
}
ZySdk.sdkExit(activity, object : ZySdkCallback {
override fun onResult(result: String) {
if (result.optBoolean("success")) {
save() //保存进度
exitProcess(0) // 结束进程
} else {
// 用户取消,或失败时查看 errorMsg / errorCode
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**回参**
......@@ -483,17 +494,19 @@ ZySdk.sdkExit(activity) { result ->
只需调用,若有更新,会弹出各渠道sdk自带的更新弹窗。
```kotlin
ZySdk.sdkUpdate(this) { result ->
ZySdk.sdkUpdate(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**回参**
......@@ -510,22 +523,28 @@ ZySdk.sdkUpdate(this) { result ->
显示浮窗
```kotlin
ZySdk.sdkShowFloat(this) { result ->
}
ZySdk.sdkShowFloat(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
})
```
隐藏浮窗
```kotlin
ZySdk.sdkHideFloat(this) { result ->
}
ZySdk.sdkHideFloat(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
})
```
**入参**
| 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) |
| 字段 | 类型 | 含义 |
|:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 |
| `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
>该功能由各渠道sdk控制,并不一定能生效,如华为sdk调用就不会弹出浮窗。
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论