我已经从以下网址实现了计费库 https://developer.android.com/google/play/billing/billing_library_overview#java
我在这一行遇到错误
if (billingResult.getResponseCode() == BillingResponse.OK) {
它说无法解析符号“BillingResponse”
这是上面链接中的完整代码
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingResponse.OK) {
// The BillingClient is ready. You can query purchases here.
}
}
@Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
我在我的应用程序 build.gradle
文件中添加了以下依赖项
dependencies {
...
implementation 'com.android.billingclient:billing:2.1.0'
}
但我收到错误
我什至无法手动导入
import com.android.billingclient.api.BillingClient.BillingResponse;
我知道它的简单解决方案就是替换
BillingResponse.OK
与
BillingClient.BillingResponseCode.OK
但我的问题是为什么它没有在文档中给出?
最佳答案
我检查了源代码并找出了正确的代码。
虽然谷歌文档上的代码说 billingResult.getResponseCode() == BillingResponse.OK
它应该是 billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
因此,您需要做的就是将 BillingResponse.OK
替换为 BillingClient.BillingResponseCode.OK
关于java - 无法解析符号 'BillingResponse',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59552481/