提交 1d96b609 作者: 钱宇

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

上级 8d8acf2f
plugins { plugins {
...@@ -10,7 +10,7 @@ android { ...@@ -10,7 +10,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "com.zwgame.test.gamecenterdemo" applicationId = "com.zwgame.test.gamecenterdemo"
minSdk = 30 minSdk = 24
targetSdk = 36 targetSdk = 36
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
......
package com.zwgame.test.gamecenterdemo 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.os.Bundle
import android.util.Log import android.util.Log
import android.widget.TextView import android.widget.TextView
...@@ -18,6 +16,8 @@ class MainActivity : AppCompatActivity() { ...@@ -18,6 +16,8 @@ class MainActivity : AppCompatActivity() {
private lateinit var statusText: TextView private lateinit var statusText: TextView
private var busy = false private var busy = false
private val TAG = "gamecenter_demo"
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false) WindowCompat.setDecorFitsSystemWindows(window, false)
...@@ -50,9 +50,11 @@ class MainActivity : AppCompatActivity() { ...@@ -50,9 +50,11 @@ class MainActivity : AppCompatActivity() {
private fun onInitClick() = guardBusy { private fun onInitClick() = guardBusy {
statusText.setText(R.string.status_init_clicked) statusText.setText(R.string.status_init_clicked)
ZySdk.sdkInit(this) { result -> ZySdk.sdkInit(this, true, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkInit if (isFinishing)
return
Log.i(TAG, "sdkInit result=$result") Log.i(TAG, "sdkInit result=$result")
statusText.text = result statusText.text = result
...@@ -62,25 +64,35 @@ class MainActivity : AppCompatActivity() { ...@@ -62,25 +64,35 @@ class MainActivity : AppCompatActivity() {
val channelCode = obj.optString("channelCode") val channelCode = obj.optString("channelCode")
Log.i(TAG, "init 成功,当前渠道:$channelCode") Log.i(TAG, "init 成功,当前渠道:$channelCode")
} else { } else {
Log.w(TAG, "init 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}") Log.w(
TAG,
"init 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
} }
} }
})
} }
private fun onLoginClick() = guardBusy { private fun onLoginClick() = guardBusy {
statusText.setText(R.string.status_login_clicked) statusText.setText(R.string.status_login_clicked)
ZySdk.sdkLogin(this) { result -> ZySdk.sdkLogin(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkLogin if (isFinishing)
return
Log.i(TAG, "sdkLogin result=$result") Log.i(TAG, "sdkLogin result=$result")
statusText.text = result statusText.text = result
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
if (!success) { if (!success) {
Log.w(TAG, "login 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}") Log.w(
TAG,
"login 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
} }
} }
})
} }
private fun onReportUserClick() = guardBusy { private fun onReportUserClick() = guardBusy {
...@@ -107,9 +119,11 @@ class MainActivity : AppCompatActivity() { ...@@ -107,9 +119,11 @@ class MainActivity : AppCompatActivity() {
put("ext", "") put("ext", "")
put("playerId", "1") put("playerId", "1")
}.toString() }.toString()
ZySdk.sdkReportRole(this, roleJson) { result -> ZySdk.sdkReportRole(this, roleJson, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkReportRole if (isFinishing)
return
Log.i(TAG, "sdkReportRole result=$result") Log.i(TAG, "sdkReportRole result=$result")
statusText.text = result statusText.text = result
...@@ -118,17 +132,26 @@ class MainActivity : AppCompatActivity() { ...@@ -118,17 +132,26 @@ class MainActivity : AppCompatActivity() {
if (success) { if (success) {
Log.i(TAG, "reportRole 成功") Log.i(TAG, "reportRole 成功")
} else { } else {
Log.w(TAG, "reportRole 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}") Log.w(
TAG,
"reportRole 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${
obj.optInt("errorCode")
}"
)
} }
} }
})
} }
private fun onUpgradeClick() = guardBusy { private fun onUpgradeClick() = guardBusy {
statusText.setText(R.string.status_upgrade_clicked) statusText.setText(R.string.status_upgrade_clicked)
ZySdk.sdkUpdate(this) { result -> ZySdk.sdkUpdate(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkUpdate if (isFinishing)
return
} }
})
} }
private fun onPayClick() = guardBusy { private fun onPayClick() = guardBusy {
...@@ -158,35 +181,51 @@ class MainActivity : AppCompatActivity() { ...@@ -158,35 +181,51 @@ class MainActivity : AppCompatActivity() {
put("attach", "sdk2_mock_attach") put("attach", "sdk2_mock_attach")
put("callbackUrl", Constant.Order.CALLBACK_OPPO) put("callbackUrl", Constant.Order.CALLBACK_OPPO)
}.toString() }.toString()
ZySdk.sdkPay(this, payJson) { result -> ZySdk.sdkPay(this, payJson, callback = object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkPay if (isFinishing)
return
Log.i(TAG, "sdkPay result=$result") Log.i(TAG, "sdkPay result=$result")
statusText.text = result statusText.text = result
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
if (!success) { if (!success) {
Log.w(TAG, "pay 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}") Log.w(
TAG,
"pay 失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}"
)
} }
} }
})
} }
private fun onShowFloatClick() { private fun onShowFloatClick() {
statusText.setText(R.string.status_show_float_clicked) statusText.setText(R.string.status_show_float_clicked)
ZySdk.sdkShowFloat(this) { } ZySdk.sdkShowFloat(this, object : ZySdkCallback {
override fun onResult(result: String) {
}
})
} }
private fun onHideFloatClick() { private fun onHideFloatClick() {
statusText.setText(R.string.status_hide_float_clicked) 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 { private fun onExitClick() = guardBusy {
statusText.setText(R.string.status_exit_clicked) statusText.setText(R.string.status_exit_clicked)
ZySdk.sdkExit(this) { result -> ZySdk.sdkExit(this, object : ZySdkCallback {
override fun onResult(result: String) {
releaseBusy() releaseBusy()
if (isFinishing) return@sdkExit if (isFinishing)
return
Log.i(TAG, "sdkExit result=$result") Log.i(TAG, "sdkExit result=$result")
statusText.text = result statusText.text = result
...@@ -197,16 +236,21 @@ class MainActivity : AppCompatActivity() { ...@@ -197,16 +236,21 @@ class MainActivity : AppCompatActivity() {
save() save()
// exitProcess(0) // exitProcess(0)
} else { } else {
Log.i(TAG, "退出取消或失败 errorMsg=${obj.optString("errorMsg")} errorCode=${obj.optInt("errorCode")}") Log.i(
TAG,
"退出取消或失败 errorMsg=${obj.optString("errorMsg")} errorCode=${
obj.optInt("errorCode")
}"
)
} }
} }
})
} }
private fun save() { private fun save() {
//保存进度 //保存进度
} }
private companion object { private companion object {
private const val TAG = "MainActivity" private const val TAG = "MainActivity"
} }
......
# Game Center SDK 接入说明V1.0.0.0 # Game Center SDK 接入说明V1.0.0.0
...@@ -149,7 +149,8 @@ plugins { ...@@ -149,7 +149,8 @@ plugins {
在Activity进行初始化,且只初始化一次。 在Activity进行初始化,且只初始化一次。
```kotlin ```kotlin
ZySdk.sdkInit(activity) { result -> ZySdk.sdkInit(activity, true, object : ZySdkCallback {
override fun onResult(result: String) {
// 初始化结果:成功/失败信息与错误码等 // 初始化结果:成功/失败信息与错误码等
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
...@@ -161,15 +162,17 @@ ZySdk.sdkInit(activity) { result -> ...@@ -161,15 +162,17 @@ ZySdk.sdkInit(activity) { result ->
val errorCode = obj.optInt("errorCode") val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}") Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
} }
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:----------------------:| |:--------------------------:|:-------------:|:--------------------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 初始化结果回调(JsonObject字符串) | | `showLoginBackgroundImage` | Boolean | 为 true 时,登录等界面会套用在 SDK 中配置的登录背景图 |
| `callback` | ZySdkCallback | 初始化结果回调(JsonObject字符串) |
**回参** **回参**
...@@ -198,7 +201,8 @@ ZySdk.sdkInit(activity) { result -> ...@@ -198,7 +201,8 @@ ZySdk.sdkInit(activity) { result ->
用于拉起渠道账号体系或聚合登录流程,成功返回参数请传给游戏服完成鉴权与建号。 用于拉起渠道账号体系或聚合登录流程,成功返回参数请传给游戏服完成鉴权与建号。
```kotlin ```kotlin
ZySdk.sdkLogin(activity) { result -> ZySdk.sdkLogin(activity, object : ZySdkCallback {
override fun onResult(result: String) {
// id、token等 // id、token等
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
...@@ -210,15 +214,16 @@ ZySdk.sdkLogin(activity) { result -> ...@@ -210,15 +214,16 @@ ZySdk.sdkLogin(activity) { result ->
val errorCode = obj.optInt("errorCode") val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}") Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
} }
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:---------------------:| |:----------:|:-------------:|:---------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 登录结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 登录结果回调(JsonObject字符串) |
**回参** **回参**
...@@ -287,7 +292,8 @@ ZySdk.sdkLogin(activity) { result -> ...@@ -287,7 +292,8 @@ ZySdk.sdkLogin(activity) { result ->
在登录成功、切换角色等操作后需进行角色信息上报。 在登录成功、切换角色等操作后需进行角色信息上报。
```kotlin ```kotlin
ZySdk.sdkReportRole(activity, roleJson) { result -> ZySdk.sdkReportRole(activity, roleJson, object : ZySdkCallback {
override fun onResult(result: String) {
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
if (success) { if (success) {
...@@ -297,16 +303,17 @@ ZySdk.sdkReportRole(activity, roleJson) { result -> ...@@ -297,16 +303,17 @@ ZySdk.sdkReportRole(activity, roleJson) { result ->
val errorCode = obj.optInt("errorCode") val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}") Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
} }
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:| |:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `roleJson` | String | 角色信息Json字符串 | | `roleJson` | String | 角色信息Json字符串 |
| `result` | String | 结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**roleJson参数如下:** **roleJson参数如下:**
...@@ -355,7 +362,8 @@ ZySdk.sdkReportRole(activity, roleJson) { result -> ...@@ -355,7 +362,8 @@ ZySdk.sdkReportRole(activity, roleJson) { result ->
### 6. SDK支付 ### 6. SDK支付
```kotlin ```kotlin
ZySdk.sdkPay(activity, payJson) { result -> ZySdk.sdkPay(activity, payJson, object : ZySdkCallback {
override fun onResult(result: String) {
// 购买数据、签名等 // 购买数据、签名等
val obj = JSONObject(result) val obj = JSONObject(result)
val success = obj.optBoolean("success") val success = obj.optBoolean("success")
...@@ -368,16 +376,17 @@ ZySdk.sdkPay(activity, payJson) { result -> ...@@ -368,16 +376,17 @@ ZySdk.sdkPay(activity, payJson) { result ->
val errorCode = obj.optInt("errorCode") val errorCode = obj.optInt("errorCode")
Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}") Log.w(TAG, "init 失败 errorMsg=${errorMsg} errorCode=${errorCode}")
} }
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:| |:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `payJson` | String | 支付信息Json字符串 | | `payJson` | String | 支付信息Json字符串 |
| `result` | String | 结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**payJson参数如下:** **payJson参数如下:**
...@@ -450,22 +459,24 @@ ZySdk.sdkPay(activity, payJson) { result -> ...@@ -450,22 +459,24 @@ ZySdk.sdkPay(activity, payJson) { result ->
在用户点击「退出游戏」等入口时调用,在回调中可实现保存进度、退出游戏等操作。 在用户点击「退出游戏」等入口时调用,在回调中可实现保存进度、退出游戏等操作。
```kotlin ```kotlin
ZySdk.sdkExit(activity) { result -> ZySdk.sdkExit(activity, object : ZySdkCallback {
override fun onResult(result: String) {
if (result.optBoolean("success")) { if (result.optBoolean("success")) {
save() //保存进度 save() //保存进度
exitProcess(0) // 结束进程 exitProcess(0) // 结束进程
} else { } else {
// 用户取消,或失败时查看 errorMsg / errorCode // 用户取消,或失败时查看 errorMsg / errorCode
} }
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:| |:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**回参** **回参**
...@@ -483,17 +494,19 @@ ZySdk.sdkExit(activity) { result -> ...@@ -483,17 +494,19 @@ ZySdk.sdkExit(activity) { result ->
只需调用,若有更新,会弹出各渠道sdk自带的更新弹窗。 只需调用,若有更新,会弹出各渠道sdk自带的更新弹窗。
```kotlin ```kotlin
ZySdk.sdkUpdate(this) { result -> ZySdk.sdkUpdate(this, object : ZySdkCallback {
override fun onResult(result: String) {
} }
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:| |:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
**回参** **回参**
...@@ -510,22 +523,28 @@ ZySdk.sdkUpdate(this) { result -> ...@@ -510,22 +523,28 @@ ZySdk.sdkUpdate(this) { result ->
显示浮窗 显示浮窗
```kotlin ```kotlin
ZySdk.sdkShowFloat(this) { result -> ZySdk.sdkShowFloat(this, object : ZySdkCallback {
} override fun onResult(result: String) {
}
})
``` ```
隐藏浮窗 隐藏浮窗
```kotlin ```kotlin
ZySdk.sdkHideFloat(this) { result -> ZySdk.sdkHideFloat(this, object : ZySdkCallback {
} override fun onResult(result: String) {
}
})
``` ```
**入参** **入参**
| 字段 | 类型 | 含义 | | 字段 | 类型 | 含义 |
|:----------:|:--------:|:-------------------:| |:----------:|:-------------:|:-------------------:|
| `activity` | Activity | 当前 Activity 上下文 | | `activity` | Activity | 当前 Activity 上下文 |
| `result` | String | 结果回调(JsonObject字符串) | | `callback` | ZySdkCallback | 结果回调(JsonObject字符串) |
>该功能由各渠道sdk控制,并不一定能生效,如华为sdk调用就不会弹出浮窗。 >该功能由各渠道sdk控制,并不一定能生效,如华为sdk调用就不会弹出浮窗。
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论