gpt4 book ai didi

android - 使用 AIDL 并将响应返回给另一个应用程序

转载 作者:太空狗 更新时间:2023-10-29 14:36:40 25 4
gpt4 key购买 nike

我在市场项目中使用 AIDL 进行支付和发送分数然后我返回 orderID 以检查结果付款当开发人员发送请求时,我将她的请求发送到服务器并收到 orderID 返回给开发人员在有趣的 resultPay 中,我向我们的服务器发送一个请求,以使用 orderID 获取结果付款,而响应尚未返回,我必须返回结果

class DeveloperApiService : Service() {


private val binder = object : ITiroDevApi.Stub() {
override fun resultPay(token: String?, orderId: String?): String {
var result = ""
ServiceHelper.resultPayment(ActiveOwner(), GamerSharedPreferenceHelper(applicationContext).userID
, orderId, token,
object : CustomObserver<ServiceHelper.StringResult>() {
override fun onError(e: Throwable?) {
super.onError(e)
result = "tryAgain"
}

override fun onNext(response: ServiceHelper.StringResult?) {
super.onNext(response)
if (response!!.result != "") {
result = response.result
} else {
when (response.error) {
"error_token_invalid_or_expired" -> result = "error_token_invalid_or_expired"
"error_payment_not_verified" -> result = "error_payment_not_verified"
}
}
}
})

if (result == "") Thread.sleep(2000)
return result

}


override fun requestPay(token: String?, price: String?): String {
var result = ""
ServiceHelper.requestPayment(ActiveOwner(), token, GamerSharedPreferenceHelper(applicationContext).userID
, price,
object : CustomObserver<ServiceHelper.StringResult>() {
override fun onError(e: Throwable?) {
super.onError(e)
result = "tryAgain"
}

override fun onNext(response: ServiceHelper.StringResult?) {
super.onNext(response)
if (response!!.result != "") {
result = response.result
inAppPayment(GamerSharedPreferenceHelper(applicationContext).userID, response.result, token!!)
}
when (response.error) {
"error_token_invalid_or_expired" -> result = "error_token_invalid_or_expired"
"error_min_amount" -> result = "error_min_amount"
}
}
})


while (result == "") {
Thread.sleep(1000)
}
return result
}

private fun inAppPayment(userId: String, orderId: String, token: String) {
var result = ""
ServiceHelper.inAppPayment(ActiveOwner(), userId, orderId, token,
object : CustomObserver<ServiceHelper.StringResult>() {
override fun onError(e: Throwable?) {
super.onError(e)
}

override fun onNext(response: ServiceHelper.StringResult?) {
super.onNext(response)

when (response.error) {
"error_already_pay" -> result = ""
"error_payment_gateway" -> result = "error_payment_gateway"
}
if (response.result != "") {
val browserIntent = Intent("android.intent.action.VIEW", Uri.parse(response.result))
applicationContext.startActivity(browserIntent)
}
}
})

}

你对解决这个问题有什么建议?

最佳答案

您应该使 ServiceHelper.paymentResult 同步。

关于android - 使用 AIDL 并将响应返回给另一个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54176807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com